Eat Study Love

먹고 공부하고 사랑하라

Python 198

Linked List Loops(Python)

Linked list의 loop이 있는지 확인하는 건 1칸 씩 이동하는 slow와 2칸 씩 이동하는 Fast를 선언해서 T/F를 반환할 수 있었다고 알고 있었는데, 전체 list의 길이를 반환하는 거는 처음봤다. 일차적으로 내가 풀었을 땐 # Do not modify!class LinkedNode: def __init__(self, value): self.value = value self.next = None def hasLoop(head): if not head : return 0, True if not head.next : return 1,True slow = head fast = head.next cond = False while fast and f..

Coding_Practice 2024.08.02

Symmetric Tree[E,Tree,Depth-First Search,Breadth-First Search,Binary Tree]

https://leetcode.com/problems/symmetric-tree/description/Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). Example 1:Input: root = [1,2,2,3,4,4,3]Output: trueExample 2:Input: root = [1,2,2,null,3,null,3]Output: false Constraints:The number of nodes in the tree is in the range [1, 1000].-100  Follow up: Could you solve it both recursively..

Coding_Practice 2024.07.31

Maximum Level Sum of a Binary Tree[M,Tree,Depth-First Search,Breadth-First Search,Binary Tree]

https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.Return the smallest level x such that the sum of all the values of nodes at level x is maximal. Example 1:Input: root = [1,7,0,7,-8,null,null]Output: 2Explanation: Level 1 sum = 1.Level 2 sum = 7 + 0 = 7.Level 3 sum = 7 + -8 = -1...

Coding_Practice 2024.07.31

Binary Tree Inorder Traversal[E,Stack,Tree,Depth-First Search,Binary Tree]

https://leetcode.com/problems/binary-tree-inorder-traversal/description/Given the root of a binary tree, return the inorder traversal of its nodes' values. Example 1:Input: root = [1,null,2,3]Output: [1,3,2]Example 2:Input: root = []Output: []Example 3:Input: root = [1]Output: [1] Constraints:The number of nodes in the tree is in the range [0, 100].-100 굉장히 기초적인 것이라고 생각했던 부분들인데 모르겠다아 짜증난다.. 1. P..

Coding_Practice 2024.07.31

Convert 1D Array Into 2D Array[E,Array,Matrix,Simulation]

https://leetcode.com/problems/convert-1d-array-into-2d-array/description/You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with  m rows and n columns using all the elements from original.The elements from indices 0 to n - 1 (inclusive) of original should form the first row of the constructed 2D ..

Coding_Practice 2024.07.26

Adding Spaces to a String[M,ArrayTwo Pointers,String,Simulation]

https://leetcode.com/problems/adding-spaces-to-a-string/description/You are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. Each space should be inserted before the character at the given index.For example, given s = "EnjoyYourCoffee" and spaces = [5, 9], we place spaces before 'Y' and 'C', which are at..

Coding_Practice 2024.07.26