2496. Maximum Value of a String in an Array 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314151617181920212223242526272829class Solution {public: int maximumValue(vector<string>& strs) { int ret = -1; int count = 0; for(string str:strs) { bool leadZeros = true; bool alpha = false; for(char c:str){ if(c>=97 && c<= 122 ){ alpha = true; break; } else if(c=='0' && leadZeros) continue; else{ leadZeros = false; count = 10*count + (c-'0'); } } if(alpha) ret = max(ret, (int)str.size()); else ret = max(ret, count); count = 0; } return ret; }}; analysis time complexity O(nm) space complexity O(1)