interaseOverlapIntervals(vector<vector<int>>& intervals){ if (interval.size() == 0) return0; sort(intervals.begin(), intervals.end(), cmp); int count = 1; // 记录非交叉区间的个数 int end = intervals[0][1]; for (int i = 1; i < intervals.size(); i ++) { if (end <= intervals[i][0]) { end = intervals[i][1]; count ++; } } return intervals.size() - count; } };
classSolution { public: vector<int> partitionLabels(string S){ int hash[26] = {0}; for (int i = 0; i < S.size(); i ++) { hash[S[i] - 'a'] = i; }
vector<int> result; int left = 0; int right = 0; for (int i = 0; i < S.size(); i ++) { right = max(right, hash[S[i] - 'a']); if (i == right) { result.push_back(right - left + 1); left = i + 1; } }
classSolution { public: intmonotoneIncreasingDigits(int N){ string strNum = to_string(N); int flag = strNum.size(); for (int i = strNum.size() - 1; i > 0; i --) { if (strNum[i - 1] > strNum[i]) { flag = i; strNum[i-1] --; } } for (int i = flag; i < strNum.size(); i ++) { strNum[i] = '9'; }
classSolution { private: int result; inttraversal(TreeNode* cur){ // 空节点,该节点有覆盖 if (cur == NULL) return2; int left = traversla(cur->left); int right = traversal(cur->right);
// 情况1,左右节点都有覆盖 if (left == 2 && right == 2) return0;
// 情况2 if (left == 0 || right == 0) { result ++; return1; }
// 情况3 if (left == 1 || right == 1) return2;
return-1; }
public: intminCameraCover(TreeNode* root){ result = 0; // 情况4 if (traversal(root) == 0) { result ++; }