[Python] 238. Product of Array Except Self
·
study/LeetCode
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..
[Python] 561. Array Partition I
·
study/LeetCode
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..
[Python] 15. Two Sum
·
study/LeetCode
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(..
[Python] 1. Two Sum
·
study/LeetCode
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..