forked from GDSC-IGDTUW-Autumn-of-Code-2022/dsa-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaximum_Value.java
41 lines (34 loc) · 1.03 KB
/
Maximum_Value.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class Maximum_Value {
public static void main(String[] args) {
String[] str = { "1", "01", "001", "0001" };
int res = MaxValue(str);
System.out.println(res);
}
public static int MaxValue(String[] strs) {
int str = 0;
for (int i = 0; i < strs.length; i++) {
String s = strs[i];
char[] chr = s.toCharArray();
int countDigit = 0;
int countString = 0;
int convert = 0;
int sum = 0;
int max = 0;
for (int j = 0; j < chr.length; j++) {
if (Character.isDigit(chr[j])) {
countDigit++;
} else {
countString++;
}
}
if (countDigit == chr.length) {
convert = Integer.parseInt(s);
} else {
sum = countDigit + countString;
}
max = Math.max(sum, convert);
str = Math.max(str, max);
}
return str;
}
}