标签:code public div val etc solution ring size 优化
1 class Solution 2 { 3 public: 4 bool isValid(string S) 5 { 6 if(S.size()%3!=0||S[0]!=‘a‘) 7 return false; 8 int times = 6900; 9 int presize = S.size(); 10 while(S.size() && times--) 11 { 12 for(int i = 0;i < S.size()-2;i ++) 13 { 14 if(S[i]==‘a‘&&S[i+1]==‘b‘&&S[i+2]==‘c‘) 15 { 16 S.erase(i,3); 17 break; 18 } 19 } 20 if(S.size()==presize) 21 break; 22 } 23 return S.size()==0; 24 } 25 };
随便模拟了一下,加了点优化,能过是真的神秘
Leetcode-1003 Check If Word Is Valid After Substitutions(检查替换后的词是否有效)
标签:code public div val etc solution ring size 优化
原文地址:https://www.cnblogs.com/Asurudo/p/10464603.html