classSolution { public: intmaximumValue(vector<string>& strs){ int res = 0; for (auto& s : strs) { bool isDigits = true; for (char& c : s) { isDigits &= isdigit(c); } res = max(res, isDigits ? stoi(s) : (int)s.size()); } return res; } };
[sol1-Java]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
classSolution { publicintmaximumValue(String[] strs) { intres=0; for (String s : strs) { booleanisDigits=true; intn= s.length(); for (inti=0; i < n; ++i) { isDigits &= Character.isDigit(s.charAt(i)); } res = Math.max(res, isDigits ? Integer.parseInt(s) : n); } return res; } }
[sol1-C#]
1 2 3 4 5 6 7 8 9 10 11 12 13
publicclassSolution { publicintMaximumValue(string[] strs) { int res = 0; foreach (string s in strs) { bool isDigits = true; foreach (char c in s) { isDigits &= char.IsDigit(c); } res = Math.Max(res, isDigits? int.Parse(s) : s.Length); } return res; } }
[sol1-Python3]
1 2 3 4 5 6 7
classSolution: defmaximumValue(self, strs: List[str]) -> int: res = 0 for s in strs: is_digits = all(c.isdigit() for c in s) res = max(res, int(s) if is_digits elselen(s)) return res
[sol1-JavaScript]
1 2 3 4 5 6 7 8 9 10 11
var maximumValue = function(strs) { let res = 0; for (const s of strs) { let isDigits = true; for (const c of s) { isDigits &= c >= '0' && c <= '9'; } res = Math.max(res, isDigits ? Number(s) : s.length); } return res; };
funcmax(a int, b int)int { if a > b { return a } return b }
funcmaximumValue(strs []string)int { res := 0 for _, s := range strs { isDigits := true for _, c := range s { isDigits = isDigits && (c >= '0' && c <= '9') } if isDigits { v, _ := strconv.Atoi(s) res = max(res, v) } else { res = max(res, len(s)) } } return res }
[sol1-C]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
intmaximumValue(char ** strs, int strsSize){ int res = 0; for (int i = 0; i < strsSize; i++) { bool isDigits = true; for (int j = 0; j < strlen(strs[i]); j++) { isDigits &= strs[i][j] >= '0' && strs[i][j] <= '9'; } if (isDigits) { res = fmax(res, atoi(strs[i])); } else { res = fmax(res, strlen(strs[i])); } } return res; }