We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d562796 commit d0e4802Copy full SHA for d0e4802
Easy/Second Largest Digit in a String.java
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ public int secondHighest(String s) {
3
+ int maximumNum = -1;
4
+ int secondMaximumNum = -1;
5
+ for (char c : s.toCharArray()) {
6
+ if (Character.isDigit(c)) {
7
+ int num = Character.getNumericValue(c);
8
+ if (maximumNum < num) {
9
+ if (secondMaximumNum < maximumNum) {
10
+ secondMaximumNum = maximumNum;
11
+ }
12
+ maximumNum = num;
13
+ } else if (secondMaximumNum < num && num < maximumNum) {
14
+ secondMaximumNum = num;
15
16
17
18
+ return secondMaximumNum;
19
20
+}
0 commit comments