Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- programmers
- 맥북
- gs25
- Baekjoon
- Docker
- Real or Not? NLP with Disaster Tweets
- 캐치카페
- dacon
- github
- AI 경진대회
- leetcode
- 코로나19
- ChatGPT
- Git
- 금융문자분석경진대회
- 프로그래머스
- 편스토랑 우승상품
- 데이콘
- 우분투
- 더현대서울 맛집
- Kaggle
- ubuntu
- SW Expert Academy
- hackerrank
- 백준
- 자연어처리
- 편스토랑
- 프로그래머스 파이썬
- PYTHON
- 파이썬
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 345. Reverse Vowels of a String (Python) 본문
728x90
반응형
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Input: "hello"
Output: "holle"
Example 2:
Input: "leetcode"
Output: "leotcede"
Note:
The vowels does not include the letter "y".
Solution
class Solution(object):
def reverseVowels(self, s):
s_list = list(s)
vowels = []
for i, val in enumerate(s_list):
if val in ['a', 'o', 'e', 'i', 'u', 'A', 'O', 'E', 'I', 'U']:
vowels.append((i, val))
for j in range(len(vowels)//2):
s_list[vowels[j][0]] = vowels[len(vowels)-j-1][1]
s_list[vowels[len(vowels)-j-1][0]] = vowels[j][1]
return ''.join(s_list)
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 916. Word Subsets (Python) (0) | 2020.08.09 |
---|---|
[leetCode] 551. Student Attendance Record I (Python) (0) | 2020.08.08 |
[leetCode] 448. Find All Numbers Disappeared in an Array (Python) (0) | 2020.08.06 |
[leetCode] 35. Search Insert Position (Python) (0) | 2020.08.05 |
[leetCode] 290. Word Pattern (Python) (0) | 2020.08.04 |
Comments