标签:turn ons close pen 题目 class 最大 sed 最小
题目链接:https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray/
略.
1 const int inf = 0x7fffffff; 2 3 class Solution { 4 public: 5 int findUnsortedSubarray(vector<int>& nums) { 6 int L = 0, R = -1; 7 int N = nums.size(); 8 int maxNum = -inf, minNum = inf; 9 10 for(int i = 0; i < N; ++i) { 11 if(maxNum <= nums[i]) maxNum = nums[i]; 12 else R = i; 13 } 14 15 for(int i = N - 1; i >= 0; --i) { 16 if(minNum >= nums[i]) minNum = nums[i]; 17 else L = i; 18 } 19 20 return R - L + 1; 21 } 22 };
标签:turn ons close pen 题目 class 最大 sed 最小
原文地址:https://www.cnblogs.com/zaq19970105/p/11475160.html