mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
init
This commit is contained in:
20
greed/581.h
Normal file
20
greed/581.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <limits.h>
|
||||
|
||||
int findUnsortedSubarray(int* nums, int numsSize) {
|
||||
int n = numsSize;
|
||||
int maxn = INT_MIN, right = -1;
|
||||
int minn = INT_MAX, left = -1;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (maxn > nums[i]) {
|
||||
right = i;
|
||||
} else {
|
||||
maxn = nums[i];
|
||||
}
|
||||
if (minn < nums[n - i - 1]) {
|
||||
left = n - i - 1;
|
||||
} else {
|
||||
minn = nums[n - i - 1];
|
||||
}
|
||||
}
|
||||
return right == -1 ? 0 : right - left + 1;
|
||||
}
|
||||
Reference in New Issue
Block a user