본문 바로가기
python-algorithm

Leetcode 1859. Sorting the Sentence

by 무적김두칠 2021. 7. 16.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution:
    def sortSentence(self, s: str-> str:
        tmp=list(map(str, s.split()))
        ans=[0]*len(tmp)
        nums="0123456789"
        for i in range (len(tmp)):
            for j in nums:
                if j in tmp[i]: 
                    tmp1=tmp[i].replace(j,"")
                    ans[int(j)-1]=tmp1
        ansStr=ans[0]
        for i in range(1,len(ans)):
            ansStr=ansStr+" "+ans[i]
        return ansStr
cs
반응형

댓글