mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
22 lines
559 B
C++
22 lines
559 B
C++
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
|