leetcode2 LeetCode 206. Reverse Linked List - Python LeetCode 206. Reverse Linked List - Python Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Solution: class Solution(object): def reverseList(self, head): prev = None curr = head while curr!= None: tmp = curr.next curr.next = prev prev = curr curr = tmp return prev (참고 사이트) 링크드리스트 역순 재배열 : https://www.youtube.com/watch?v=gf_BiXt4YlQ 2020. 8. 11. LeetCode 226. Invert Binary Tree - Python LeetCode 226. Invert Binary Tree - Python Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Solution : class Solution(object): def invertTree(self, root): stack = [root] while stack: node = stack.pop() if node: node.left, node.right = node.right, node.left stack += node.left, node.right return root (솔루션 출처) https://gist.github.com/ryuji0123/ 더보기 # .. 2020. 8. 9. 이전 1 다음