leetcode (25) 썸네일형 리스트형 [기타] 릿코드 Easy 557 'Reverse Words in a String III' (Python) https://leetcode.com/problems/reverse-words-in-a-string-iii/ 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 문자열의 띄어쓰기를 기준으로 각 단어들이 뒤집으면 된다. class Solution: def reverseWords(self, s: str) -> str: answer = '' for i in s.split(): answer += (i[::-1] + '.. [기타] 릿코드 Easy 344 'Reverse String' (Python) https://leetcode.com/problems/reverse-string/ 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 문자열 길이의 반만큼 양 쪽 문자를 스와프 해주면 됨 class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ for i in range(len(.. [정렬] 릿코드 Easy 167 'Two Sum II - Input Array Is Sorted' (Python) https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ Two Sum II - Input Array Is Sorted - 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 효율적인 알고리즘을 위해 bisect 라이브러리를 사용 양수가 포함될 때와 음수(0 포함)만 있을 때 나눠서 코딩 from bisect import bisect_right, bisect_left class Solution: def twoS.. [정렬] 릿코드 Easy 283 'Move Zeroes' (Python) https://leetcode.com/problems/move-zeroes/ Move Zeroes - 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 파이썬 배열의 내장 메소드를 사용 class Solution: def moveZeroes(self, nums: List[int]) -> None: """ Do not return anything, modify nums in-place instead. """ for i in range(nums.count(0)): nu.. [정렬] 릿코드 Medium 189 'Rotate Array' (Python) https://leetcode.com/problems/rotate-array/ Rotate Array - 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 k번만큼 제일 오른쪽 값을 왼쪽으로 옮기는걸 반복하면 됨 class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ for i in range.. [정렬] 릿코드 Easy 977 'Squares of a Sorted Array' (Python) https://leetcode.com/problems/squares-of-a-sorted-array/ Squares of a Sorted Array - 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 리스트의 각 값에 연산을 해야 하므로 벡터연산이 가능한 numpy를 import 함 import numpy as np class Solution: def sortedSquares(self, nums: List[int]) -> List[int]: answer = np... [이분탐색] 릿코드 Easy 35 'Search Insert Position' (Python) https://leetcode.com/problems/search-insert-position/ Search Insert Position - 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. 정렬된 배열에 값을 넣으면 그 값에 대한 인덱스를 찾아주는 파이썬 라이브러리 사용 from bisect import bisect_left class Solution: def searchInsert(self, nums: List[int], target: int) -> int.. [이분탐색] 릿코드 Easy 278 'First Bad Version' (Python) https://leetcode.com/problems/first-bad-version/ First Bad Version - 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 원소의 값이 크기 때문에 이분 탐색으로 정답을 찾아야 함 # The isBadVersion API is already defined for you. # @param version, an integer # @return an integer # def isBadVersion(version): cla.. 이전 1 2 3 4 다음