Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd0e4802

Browse files
authored
Added Second Largest Digit in a String.java
1 parentd562796 commitd0e4802

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
classSolution {
2+
publicintsecondHighest(Strings) {
3+
intmaximumNum = -1;
4+
intsecondMaximumNum = -1;
5+
for (charc :s.toCharArray()) {
6+
if (Character.isDigit(c)) {
7+
intnum =Character.getNumericValue(c);
8+
if (maximumNum <num) {
9+
if (secondMaximumNum <maximumNum) {
10+
secondMaximumNum =maximumNum;
11+
}
12+
maximumNum =num;
13+
}elseif (secondMaximumNum <num &&num <maximumNum) {
14+
secondMaximumNum =num;
15+
}
16+
}
17+
}
18+
returnsecondMaximumNum;
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp