분류 전체보기(104)
-
[Python] sys.maxsize - 최대 정수값
sys.maxsize python3에서 int의 최댓값은 sys를 import한 다음 maxsize를 구해보면 알 수 있다. import sys test = sys.maxsize print(test) list1 = range(test) print(len(list1)) """ 2147483647 2147483647 """python3이상에선 int형을 초과할 경우 자동으로 long으로 변환되기 때문에 다음과 같은 연산도 가능하다. # 최대 정수값 초과시 long으로 자동 변환 test += 1 print(test) """ 2147483648 """반면 int의 최댓값을 초과하게 되면 list를 생성 할 수 없다. list2 = range(test) print(len(list2)) """ OverflowEr..
2021.01.11 -
[LeetCode] 238. Product of Array Except Self
https://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 List class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: left = [] right = [] result = [] # 왼쪽 곱셈 ..
2021.01.10 -
[LeetCode] 561. Array Partition I
https://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 내 풀이 1 class Solution: def arrayPairSum(self, nums: List[int]) -> int: nums.sort(reverse=True) sum = 0 for i in range(1, len(nums), 2): sum += nums[i] return sum 내림차..
2021.01.10 -
[LeetCode] 15. 3Sum
https://leetcode.com/problems/3sum/ 3Sum - 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 List class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: if len(nums) < 3: return [] triplets = [] nums.sort() for i in range(len(nums) - 2): if i ..
2021.01.10 -
[Python] if not x
파이썬의 if not x 조건에 맞는 x는 (즉, False로 판단되는 것은) 빈 리스트 [] 빈 튜플 () 빈 문자열 "" False 0 None 등이 있다. if not []: print(bool([])) if not (): print(bool(())) if not "": print(bool("")) if not False: print(bool(False)) if not 0: print(bool(0)) if not None: print(bool(None)) """ False False False False False False """
2021.01.08 -
[LeetCode] 1. Two Sum
https://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 내 풀이 1 class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: index = [] for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i] + nums[j] == target:..
2021.01.07