Skip to content

Commit 08c72fd

Browse files
committed
Runtime: 80 ms (Top 5.3%) | Memory: 16.30 MB (Top 72.1%)
1 parent 64c8d4e commit 08c72fd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
# Runtime: 80 ms (Top 5.3%) | Memory: 16.30 MB (Top 72.1%)
2+
13
class Solution:
24
def secondHighest(self, s: str) -> int:
3-
s=set(s)
4-
a=[]
5-
for i in s:
6-
if i.isnumeric() :
7-
a.append(int(i))
8-
a.sort()
9-
if len(a)<2:
10-
return -1
11-
return a[len(a)-2]
5+
nums = []
6+
for char in s:
7+
if char.isdigit():
8+
nums.append(int(char))
9+
nums = [num for num in nums if num != max(nums)]
10+
if len(nums) >= 1: return max(nums)
11+
else: return -1

0 commit comments

Comments
 (0)