Day4 Two Pointers - LeetCode 14day

2022. 12. 15. 16:39Post

class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        s.reverse()

https://leetcode.com/problems/reverse-string/?envType=study-plan&id=algorithm-i 

 

Reverse String - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

파이썬으로 문자열 뒤집기

쉽다.

그래서 알고리즘 문제풀때는 파이썬 쓰나보다. 

 

검색해보니 주로 선택하는 방법에는 나처럼 built-in 펑션으로 reverse를 사용하는 방법 하나와, for-loop을 사용. 혹은 slice를 사용해서도 하는거같다. 

 

파이썬이 편하구나.

 

class Solution:
    def reverseWords(self, s: str) -> str:
        """
        ' '로 문자열에서 단어를 나누어 배열로 만든다. 
        단어들을 거꾸로 한다. 
        거꾸로 만든단어들을 배열로 만들어 리턴한다.
        """
        words = s.split(' ')
        return_string = str()            
        for idx, word in enumerate(words):
            r_word = word[::-1]
            return_string += r_word
            if idx != len(words)-1:
                return_string += ' '
        return return_string

https://leetcode.com/problems/reverse-words-in-a-string-iii/?envType=study-plan&id=algorithm-i 

 

Reverse Words in a String III - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

음 이거 1분만에도 풀수있는 문제인데, 5분 걸려 풀었다. 문제 잘못 이해해서.

확실히 영어니까 겪는 어려움도 조금 있는듯

'Post' 카테고리의 다른 글

2022년 12월 공부  (0) 2022.12.28
TypeScript 를 쓰는 이유  (3) 2022.12.21
Day3 Two Pointers - LeetCode 14day (Time Limit Exceeded로 실패)  (0) 2022.12.15
Day2 Two Pointers - LeetCode 14day  (2) 2022.12.13
Day1 Binary Search - LeetCode 14day  (0) 2022.12.12