lao1 me
AI服务器日常推广公告
搜索
菜单
主题回帖收藏
  • 魔法师
    Leetcode每日一题 —— 3942. 排序排列的最少操作数
    把0换到开头,判有没有排序;注意反转2次可以右旋``` class Solution { public: int minOperations(vector<int>& v) { #define L v.begin() #define R v.end() int p0=find(L,R,0)-L,n=v.size(); rotate(L,L+p0,R); if(is_sorted(L,R))retu
    魔法师4天前AI5宙读之魔术士
    AI
  • SomeBottle
    Leetcode每日一题 —— 3863. 将一个字符串排序的最小操作次数
    最多操作三次(右左右)``` class Solution { public: int dfs(int d,string s,int l,int r){ if(d>=3)return 3; if(l||r)sort(s.begin()+l,s.end()-r); if(is_sorted(s.begin(),s.end()))return d; if(s.size()==2)return -1;
    SomeBottle5天前AI3tiansuohaoer
    AI
  • 魔法师
    Leetcode每日一题 —— 3727. 最大交替平方和
    贪心,用nth_element求第k大可以做到O(n)``` class Solution { public: long long maxAlternatingSum(vector<int>& v) { long long res=0,n=v.size(); for(auto &w:v){ w*=w; res+=w; } nth_element(v.begin(),v.begin()+n/2,v.
    魔法师2026-10-13AI70wFF
    AI
  • SomeBottle
    Leetcode每日一题 —— 856. 括号的分数
    按深度分别计算得分``` class Solution { public: int scoreOfParentheses(string s) { vector<int> f(55,0); int it=0; for(auto c:s){ if(c=='('){ it++; f[it+1]=0; } else{ f[it]+=max(1,f[it+1]*2); it--; } } return f[
    SomeBottle2026-10-05AI2tiansuohaoer
    AI
  • SomeBottle
    Leetcode每日一题 —— 678. 有效的括号字符串
    贪心地把左括号和右括号填满,如果是奇数就留个*``` class Solution { public: bool checkValidString(string s) { int n=s.size(),li=n/2,p=0; for(auto c:s)if(c=='(')li--; for(auto c:s){ if(c=='*'){ if(li>0)li--,c='('; else if(n&1
    SomeBottle2026-10-04AI3咪帕
    AI
tiansuohaoer
tiansuohaoer
Lv1 · lao1 0
TA的主题TA的回帖我的称号TA的收藏
提示