Skip to content

Commit ec69d56

Browse files
authored
Create 1796. Second Largest Digit in a String
1 parent d132c4f commit ec69d56

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
int secondHighest(string s)
4+
{
5+
string temp;
6+
7+
for(int i=0; i<s.length(); i++)
8+
{
9+
if(s[i]>=48 && s[i]<=57)
10+
temp+=s[i];
11+
}
12+
int max = 0;
13+
for(int i=0; i<temp.length(); i++)
14+
{
15+
if((temp[i]-'0') > max)
16+
max = temp[i]-'0';
17+
}
18+
19+
int secondMax=-1;
20+
for(int i=0; i<temp.length(); i++)
21+
{
22+
if(secondMax < (temp[i]-'0') && (temp[i]-'0') < max)
23+
secondMax = temp[i]-'0';
24+
}
25+
return secondMax;
26+
}
27+
};

0 commit comments

Comments
 (0)