본문 바로가기
300x250

분류 전체보기268

LeetCode: 104. Maximum Depth of Binary Tree https://leetcode.com/problems/maximum-depth-of-binary-tree/description/ Maximum Depth of Binary Tree - LeetCodeCan you solve this real interview question? Maximum Depth of Binary Tree - Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leafleetcode.comGiven the root of a b.. 2025. 8. 27.
LeetCode: 100. Same Tree https://leetcode.com/problems/same-tree/description/ Given the roots of two binary trees p and q, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. Example 1:Input: p = [1,2,3], q = [1,2,3]Output: trueExample 2:Input: p = [1,2], q = [1,null,2]Output: falseExample 3:Input: p = [1,2,.. 2025. 8. 22.
LeetCode: 1337. The K Weakest Rows in a Matrix https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/description/You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row.A row i is weaker than a row j if one of the following is true:The number of soldiers in row.. 2025. 8. 20.
LeetCode: 888. Fair Candy Swap https://leetcode.com/problems/fair-candy-swap/description/Alice and Bob have a different total number of candies. You are given two integer arrays aliceSizes and bobSizes where aliceSizes[i] is the number of candies of the ith box of candy that Alice has and bobSizes[j] is the number of candies of the jth box of candy that Bob has.Since they are friends, they would like to exchange one candy box.. 2025. 8. 19.
LeetCode: 704. Binary Search https://leetcode.com/problems/binary-search/description/Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.You must write an algorithm with O(log n) runtime complexity. Example 1:Input: nums = [-1,0,3,5,9,12], target = 9Output: 4Explanation: 9 exists in.. 2025. 8. 17.
LeetCode: 441. Arranging Coins https://leetcode.com/problems/arranging-coins/description/You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.Given the integer n, return the number of complete rows of the staircase you will build. Example 1:Input: n = 5Output: 2Explanation: Because the 3rd ro.. 2025. 8. 14.
LeetCode: 349. Intersection of Two Arrays https://leetcode.com/problems/intersection-of-two-arrays/description/ Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]Output: [9,4]Explanation: [4,9] is also accepted.. 2025. 8. 13.
LeetCode: 222. Count Complete Tree Nodes https://leetcode.com/problems/count-complete-tree-nodes/Given the root of a complete binary tree, return the number of the nodes in the tree.According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.Design an algorithm .. 2025. 8. 12.
LeetCode: 35. Search Insert Position https://leetcode.com/problems/search-insert-position/description/ Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You must write an algorithm with O(log n) runtime complexity. Example 1:Input: nums = [1,3,5,6], target = 5Output: 2Example 2:Input: nums = [1,3,5,6], target.. 2025. 8. 11.
300x250