파이썬(20)
-
[LeetCode] 2. Add Two Numbers
LeetCode 2. Add Two Numbers https://leetcode.com/problems/add-two-numbers/ Add Two Numbers - 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 Solution # Definition for singly-linked list. class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next class Sol..
2021.01.14 -
[자료구조] Double Linked List (이중 연결 리스트) 구현
Double Linked List # Single Linked List class Node: def __init__(self, item, prev=None, next=None): self.item = item self.prev = prev self.next = next class DoubleLinkedList: def __init__(self): self.head = Node(None) self.tail = Node(None, self.head) self.head.next = self.tail self.size = 0 def list_size(self): return self.size def is_empty(self): if self.size != 0: return False else: return Tr..
2021.01.11 -
[자료구조] Single Linked List (단순 연결 리스트) 구현
Single Linked List (단순 연결 리스트) 파이썬으로 구현 해 보았다. # Single Linked List class Node: def __init__(self, item, next=None): self.item = item self.next = next class SingleLinkedList: def __init__(self): self.head = None self.size = 0 def list_size(self): return self.size def is_empty(self): if self.size != 0: return False else: return True def select_node(self, idx): if idx >= self.size: print("Index Er..
2021.01.11 -
[LeetCode] 121. Best Time to Buy and Sell Stock
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ Best Time to Buy and Sell Stock - 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 풀이 import collections from typing import Deque from typing import List class Solution: def maxProfit(self, prices: List[int]) -> int: if ..
2021.01.11 -
[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