728x90
๋ฌธ์ ์ ๋ชฉ | ์ ๋ต๋ฅ | ๋์ด๋ |
344. reverse-string | 76.8% | Easy |
Reverse String - LeetCode
Can you solve this real interview question? Reverse String - Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algo
leetcode.com
๋ฌธ์ ์์ฝ.
๋ฌธ์์ด์ ์ญ์์ผ๋ก ๋ฐ๊พธ๋ ํจ์๋ฅผ ์์ฑํด๋ผ
์กฐ๊ฑด 1) ์ ๋ ฅ์ ๋ฌธ์๋ก ์ด๋ฃจ์ด์ง ๋ฐฐ์ด๋ก ์ฃผ์ด์ง๋ค
Step1. ๋ฐฐ์ด ๋ค์ง๊ธฐ -> list.reverse() ์ด์ฉ
๋ฆฌ์คํธ์๋ง ํด๋น ์๋ ์ ๋ ฅ ๊ฐ์ ์ญ์์ผ๋ก ๋ณ๊ฒฝ, ๋ฐํ๊ฐ X |
list.reverse() |
๋ฆฌ์คํธ, ํํ, ์คํธ๋ง, ๋์
๋๋ฆฌ์ ์ฌ์ฉ ์ํ์ ๋ณด์กดํ๊ณ , ๋ณ๊ฒฝ๋ ๊ฐ์ ์ฃผ์๋ฅผ ๋ฐํ ๋ฐ๋ผ์ ์์ ์๋ฃํ์ ์ง์ ํด ์ฃผ์ด์ผ ํจ |
์ํ๋ ์๋ฃํ(reversed(sequence)) |
๊ตฌํ
class Solution(object):
def reverseString(self, s):
s.reverse()
return s
728x90
'์๊ณ ๋ฆฌ์ฆ๐ฅ > ๋ฌธ์ ํ์ด (Python)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode] 49. group-anagrams (Medium) 2023/4/28 (0) | 2023.04.28 |
---|---|
[LeetCode] 937. reorder-data-in-log-files (Easy) 2023/4/27 (0) | 2023.04.27 |
[LeetCode] 125. valid-palindrome (Easy) 2023/4/27 (0) | 2023.04.27 |
[python] 1. ์ฝ๋ฉํ ์คํธ์ ํ์ ์ฒดํฌ ๋ชฉ๋ก (0) | 2023.04.26 |
[python] 0. ์ฝ๋ฉ ํ ์คํธ ๊ธฐ๋ณธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ (4/26 ์ ๋ฐ์ดํธ) (0) | 2023.04.20 |