mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
leetcode new problems
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
class Solution {
|
||||
public:
|
||||
bool isTrionic(vector<int>& nums) {
|
||||
int n = nums.size(), i = 1;
|
||||
while (i < n && nums[i - 1] < nums[i]) {
|
||||
i++;
|
||||
}
|
||||
int p = i - 1;
|
||||
while (i < n && nums[i - 1] > nums[i]) {
|
||||
i++;
|
||||
}
|
||||
int q = i - 1;
|
||||
while (i < n && nums[i - 1] < nums[i]) {
|
||||
i++;
|
||||
}
|
||||
int flag = i - 1;
|
||||
return (p != 0) && (q != p) && (flag == n - 1 && flag != q);
|
||||
}
|
||||
};
|
||||
|
||||
// Uses single pointer, and checks for all 3 required segments one after one.a
|
||||
Reference in New Issue
Block a user