분류 전체보기(104)
-
[LeetCode] 20. Valid Parentheses
LeetCode 20. Valid Parentheses Solution class Solution: def isValid(self, s: str) -> bool: stack = [] bracket = { ')': '(', ']': '[', '}': '{' } for char in s: if char not in bracket: stack.append(char) # open bracket elif not stack or bracket[char] != stack.pop(): return False return len(stack) == 0 괄호 짝 딕셔너리로 설정 open bracket일경우 stack에 push open이 없거나, 짝이 안맞을 경우 return False stack에 남아있을 경우(open이..
2021.01.18 -
[LeetCode] 328. Odd Even Linked List
LeetCode 328. Odd Even Linked List Odd Even Linked List - 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 Solution: def oddEvenList(self, head: ..
2021.01.15 -
[Python] Call by.. What?
Python은 Call by assignment 이다. Call by assignment (Call by object reference) 파이썬은 immutable(불변) 자료형일 경우 call by value 처럼 처리되고, mutable(가변) 자료형일 경우 call by reference처럼 처리 된다. 이를 call by assignment 또는 call by object reference 라고 부른다. call by value, reference 파이썬의 객체(object)에 대한 이해 파이썬은 모든것이 객체(Object)이다. 라는 말, 파이썬을 배운 사람이라면 한번쯤은 들어 봤을 것이다. 과연 무슨 뜻일까? a = 10 파이썬에선 a에 10이 할당되는 것이 아니라, a가 10이라는 상수 객체..
2021.01.15 -
Call by.. what?
Call by.. 함수의 호출 방식은 크게 두가지가 있는데, 바로 Call by value와 Call by reference이다. Call by value 인자로 받은 값을 복사한다. 단지 복사만 하는 것이기 때문에 원형은 바뀌지 않는다. C // C #include void swap(int x, int y) { int tmp = x; x = y; y = tmp; } int main() { int x = 10; int y = 20; printf("x = %d, y = %d\n", x, y); swap(x, y); printf("x = %d, y = %d\n", x, y); return 0; } C++ // C++ #include using namespace std; void swap(int x, int ..
2021.01.14 -
[LeeCode] 24. Swap Nodes in Pairs
Leetcode 24. Swap Nodes in Pairs Swap Nodes in Pairs - 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 # Definition for singly-linked list. class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next class Solution: def swapPairs(self, head: ListNod..
2021.01.14 -
[Python] divmod()
divmod() ## 같은 의미 divmod(a, b) (a // b, a % b) 몫과 나머지를 tuple(튜플) 로 return한다. # 둘 다 양수 print(divmod(10, 3), '\n') # 음수가 있을 경우 print(divmod(10, -3)) print(divmod(-10, 3)) print(divmod(-10, -3), '\n') # 둘중 하나 실수 print(divmod(10.6, 3)) """ (3, 1) (-4, -2) (-4, 2) (3, -1) (3.0, 1.5999999999999996) """
2021.01.14