LeetCode 2496. 数组中字符串的最大值C#
原题链接
简单
作者:
hpstory
,
2022-12-13 13:52:31
,
所有人可见
,
阅读 117
C# api 代码
public class Solution {
public int MaximumValue(string[] strs) {
int n = strs.Length;
int result = 0;
for (int i = 0; i < n; i++){
if (int.TryParse(strs[i], out int num)){
result = Math.Max(result, num);
}
else {
result = Math.Max(result, strs[i].Length);
}
}
return result;
}
}
C# 手写判断 代码
public class Solution {
public int MaximumValue(string[] strs) {
int n = strs.Length;
int result = 0;
for (int i = 0; i < n; i++){
result = Math.Max(result, Check(strs[i]));
}
return result;
}
private int Check(string s){
int n = s.Length;
int ans = 0;
for (int i = 0; i < n; i++){
if (s[i] >= 'a' && s[i] <= 'z') return n;
ans *= 10;
ans += (s[i] - '0');
}
return ans;
}
}