본문 바로가기
python-algorithm

leetcode 1796. Second Largest Digit in a String

by 무적김두칠 2022. 4. 18.

1
2
3
4
5
6
7
8
9
class Solution:
    def secondHighest(self, s: str-> int:
        num_list=[]
        for i in s:
            if i.isdecimal() : num_list.append(int(i))
        num_list=sorted(list(set(num_list)), reverse=True)
        if len(num_list)<2: ans=-1
        else :ans = (num_list[1])
        return(ans)
cs
반응형

'python-algorithm' 카테고리의 다른 글

leetcode 504. Base 7  (0) 2022.04.18
leetcode 1752. Check if Array Is Sorted and Rotated  (0) 2022.04.18
leetcode 1154. Day of the Year  (0) 2022.04.18
leetcode 796. Rotate String  (0) 2022.04.18
leetcode 202. Happy Number  (0) 2022.04.18

댓글