分类讨论。比较暴力``` class Solution { public: int minOperations(string s) { auto t = s; sort(t.begin(),t.end()); if(s == t) { return 0; } int n = s.size(); auto minv = t[0]; auto maxv = t[n - 1]; if(minv == s
- AI
- AI贪心``` class Solution { public: long long maxAlternatingSum(vector<int>& nums) { sort(nums.begin(),nums.end(),[](const int& a, const int &b) -> bool { return abs(a) < abs(b); }); long long res = 0; int
- AI看到括号依旧喜欢递归,依旧把自己递归晕掉写半天。``` class Solution { public: int scoreOfParentheses(string s) { int n = s.size(); int idx = 0; auto solve = [&](this auto&& solve) -> int { if(idx >= n) { return 0; } if(s[idx]
- AI两趟``` class Solution { public: bool checkValidString(string s) { int buffer_count = 0,diff = 0; int n = s.size(); for(int i = 0; i < n; i++) { if(s[i] == '*') { buffer_count++; } else if(s[i] == '(')
- AI数据量小,蛮力插 `()` 了,也不知道为什么能过(还是dfs方法思路更清晰。``` class Solution { public: vector<string> generateParenthesis(int n) { vector<unordered_set<string>> v(n + 1,unordered_set<string>()); v[1].insert("()"); for(i
- AI按理来说这个级别的题目不该hard。不过依然慢..``` class Solution { public: bool hasValidPath(vector<vector<char>>& grid) { int m = grid.size(),n = grid[0].size(); vector<vector<vector<bool>>> f(m + 1,vector<vector<bool>>(
- AI这才是我该写的``` class Solution { public: string evaluate(string s, vector<vector<string>>& knowledge) { unordered_map<string,string> S; for(const auto& v : knowledge) { S[v[0]] = v[1]; } string res = ""; i
- AI简单题。``` class Solution { public: int reverseDegree(string s) { int res = 0; for(int i = 0; i < s.size(); i++) { res += (i + 1) * (26 - s[i] + 'a'); } return res; } };
- AI
- AI计算几何完全不会``` class Solution { public: bool checkOverlap(int radius, int xCenter, int yCenter, int x1, int y1, int x2, int y2) { int closestX = max(x1, min(xCenter, x2)); int closestY = max(y1, min(yCen
- AI非不重叠``` class Solution { public: bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) { return !(rec1[0] >= rec2[2] || rec1[2] <= rec2[0] || rec1[1] >= rec2[3] || rec1[3] <= rec2[1]); } };
- AI看到大伙都这么丑陋我就释怀了。。。有没有灵光一现做法。``` class Solution { public: int totalNumbers(vector<int>& digits) { unordered_set<int> s; int n = digits.size(); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { i
- AIdfs,pair维护数目和值。``` /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x
- AI最慢的一集``` class Solution { public: long long countCommas(long long n) { long long res = 0; int base = 0; long long val = 1; while(val * 1000 <= n) { res += val* 999 * base; val *= 1000; base += 1; } re
- AI一样。``` class Solution { public: int firstStableIndex(vector<int>& nums, int k) { int n = nums.size(); vector<int> suf_min(n,0); suf_min[n - 1] = nums[n - 1]; for(int i = n - 2; i >= 0; i--) { suf_min[
- AI
- AI写复杂了(``` class Solution { public: bool uniformArray(vector<int>& nums1) { sort(nums1.begin(),nums1.end()); auto judget = [&](bool f) -> bool { bool ok = false; for(int i = 0; i < nums1.size(); i++) {
- AI
- AI写了一坨``` /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x,
- AI可以归为简单题。``` class Solution { public: int minimumDeletions(vector<int>& nums) { int pmax = 0, pmin = 0; int n = nums.size(); for(int i = 0; i < n; i++) { if(nums[i] > nums[pmax]) { pmax = i; } else if(
- AI大差不差,感觉是脑筋急转弯。``` class Solution { public: bool sumGame(string num) { int lcount = 0, rcount = 0; int lv = 0, rv = 0; int n = num.size(); for(int i = 0; i < n; i++) { if(i < n / 2) { if(num[i] == '?')