bbooo

# study/LeetCode (9)

study/LeetCode 2024. 6. 16. 23:02

[Python] 2145. Count the Hidden Sequences

https://leetcode.com/problems/count-the-hidden-sequences/description/ 문제설명n개의 숫자로  구성된 differences라는 1차원 배열이 주어진다. 이 differences 배열은 값들의 차이를 의미하는 것으로 정답이 될 수 있는 리스트를 Temp 라고 할때 differences[i] = Temp[i+1] - Temp[i]이다.정답이 될 수 있는 리스트 Temp의 모든 숫자는 lower와 upper 사이에 있어야 합니다.differences와 lower,upper가 주어졌을 때 해당 조건을 만족할 수 있는 리스트의 개수를 반환하는 문제이다. 접근법0에서부터 differences값을 하나씩 더해서 누적합을 구한다. 이 과정에서 min값과 max 값을..

study/LeetCode 2021. 3. 13. 01:09

[Python] 238. Product of Array Except Self

leetcode.com/problems/product-of-array-except-self/ Product of Array Except Self - 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 풀이 from typing import * class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: result = [] p = 1 for i in range(0,len(nums)): resul..

study/LeetCode 2021. 2. 17. 19:49

[Python] 561. Array Partition I

leetcode.com/problems/array-partition-i/ Array Partition I - 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 풀이 from typing import * class Solution: def arrayPairSum(self, nums: List[int]) -> int: # 순서대로 나열을 해서 짝수번째 수만 더하면 됨 nums = sorted(nums) i, sum = 0, 0 print(nums) while i < l..

study/LeetCode 2021. 2. 17. 19:42

[Python] 15. Two Sum

leetcode.com/problems/3sum/ 풀이 from typing import * class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: # 3개의 합이 0이 되는 숫자들의 쌍을 출력 # 합이 0이 되는것이 없거나, 3개의 합이 0이 되는게 없다면 빈리스트 출력 answer_list = [] nums = sorted(nums) #nums.sort()해봤으나 sorted(nums)가 더 빠름. # 원소의 개수가 3개 이하라면 바로 return if len(nums) < 3: return answer_list # 무조건 3개의 숫자를 사용해야하기 때문에 max i는 len(nums)-2임. for i in range(len(..

study/LeetCode 2021. 1. 22. 17:30

[Python] 1. Two Sum

leetcode.com/problems/two-sum/ Two Sum - 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 풀이 from typing import * class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): j = i+1 while j < len(nums): if nums[i] + nums[j] == target: retu..

study/LeetCode 2021. 1. 15. 16:23

[Python] 819. Most Common Word

leetcode.com/problems/most-common-word/ Most Common Word - 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 mostCommonWord(self, paragraph: str, banned: List[str]) -> str: words = [word for word in re.sub(r'[^\w]', ' ', paragraph).lower().split() if word not i..

study/LeetCode 2021. 1. 15. 15:44

[Python] 937. Reorder Log Files

leetcode.com/problems/reorder-data-in-log-files/ Reorder Data in Log Files - 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 reorderLogFiles(self, logs: List[str]) -> List[str]: digits, letters = [], [] # 구분해서 리스트 넣기 for i in logs: if i.split()[1].isdigit(): ..

study/LeetCode 2021. 1. 8. 18:50

[Python] 344. Reverse String

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. """ time = len(s)/2 count = 0 while time >= 1 : time -= 1 ..