일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 개발자
- Writing
- FIT XR
- 파비최
- Daily Challenge
- Problem Solving
- English
- 링피트
- 10분
- 스탭퍼
- 잡생각
- leetcode
- 운동
- 괜찮음
- 리얼 클래스
- 읽기
- 뭐든
- 미드시청
- 30분
- 3줄정리
- 쓰릴오브파이트
- 영어원서읽기
- 영어공부
- realclass
- 화상영어
- 매일
- 만화도
- 월간
- 프로젝트
- 사이드
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.11.15 Today's Challenge 본문
https://leetcode.com/problems/sort-vowels-in-a-string/?envType=daily-question&envId=2023-11-13
Sort Vowels in a String - LeetCode
Can you solve this real interview question? Sort Vowels in a String - Given a 0-indexed string s, permute s to get a new string t such that: * All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such
leetcode.com
set을 이용해서 푸는 문제.
문제에 대해서 이해를 좀 못하긴 함 ㅠ
class Solution:
def sortVowels(self, s: str) -> str:
freq = Counter(s)
vowels = list('uoieaUOIEA')
vowels_set = set(vowels)
res = []
for c in s:
if c in vowels_set:
while freq[vowels[-1]] == 0:
vowels.pop()
res.append(vowels[-1])
freq[vowels[-1]] -= 1
else:
res.append(c)
return ''.join(res)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.11.17 Today's Challenge (0) | 2023.11.17 |
---|---|
2023.11.16 Today's Challenge (0) | 2023.11.16 |
2023.11.14 Today's Challenge (0) | 2023.11.14 |
2023.11.13 Today's Challenge (0) | 2023.11.13 |
2023.11.12 Today's Challenge (0) | 2023.11.12 |
Comments