Solved! Leetcode 958. Check Completeness of a Binary Tree

Table of ContentsProblem descriptionCheck Completeness of a Binary TreeJavaTime ComplexitySpace ComplexityPythonApproach 1Approach 2 Problem description source: https://leetcode.com/problems/check-completeness-of-a-binary-tree/description/ Check Completeness of a Binary Tree Given the root of a binary tree, determine if it is a complete binary tree. In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes ...

Solved! Leetcode 1466. Reorder Routes to Make All Paths Lead to the City Zero

source: https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/description/ Reorder Routes to Make All Paths Lead to the City Zero There are n cities numbered from 0 to n – 1 and n – 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to ...

Solved! Leetcode 2492. Minimum Score of a Path Between Two Cities

source: https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/ Minimum Score of a Path Between Two Cities You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai and bi with a distance equal ...

Solved! Leetcode 2348. Number of Zero-Filled Subarrays

source: https://leetcode.com/problems/number-of-zero-filled-subarrays/description/ Number of Zero-Filled Subarrays Given an integer array nums, return the number of zero-filled subarrays. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: Input: nums = [1,3,0,0,2,0,0,4] Output: 6 Explanation: There are 4 occurrences of [0] as a subarray. There are 2 occurrences of [0,0] as a ...

Solved! Leetcode 1485. Clone Binary Tree With Random Pointer

source: https://leetcode.com/problems/clone-binary-tree-with-random-pointer/description/ Clone Binary Tree With Random Pointer A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a deep copy of the tree. The tree is represented in the same input/output way as normal binary trees where each ...

Solved! Leetcode 208. Implement Trie (Prefix Tree)

source: https://leetcode.com/problems/implement-trie-prefix-tree/ Implement Trie (Prefix Tree) A trie (pronounced as “try”) or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. Implement the Trie class: Trie() Initializes the trie object. void insert(String ...

Solved! Leetcode 129. Sum Root to Leaf Numbers

source: https://leetcode.com/problems/sum-root-to-leaf-numbers/description/ Sum Root to Leaf Numbers You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123. Return the total sum of all root-to-leaf numbers. Test ...

Solved! Leetcode 568. Maximum Vacation Days

source: https://leetcode.com/problems/maximum-vacation-days/ Maximum Vacation Days LeetCode wants to give one of its best employees the option to travel among n cities to collect algorithm problems. But all work and no play makes Jack a dull boy, you could take vacations in some particular cities and weeks. Your job is to schedule the traveling to maximize ...

Solved! Leetcode 23. Merge k Sorted Lists

Table of ContentsMerge k Sorted ListsJavaPythonTime ComplexitySpace Complexity source: https://leetcode.com/problems/merge-k-sorted-lists/ Merge k Sorted Lists You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. Example 1:Input: lists = [[1,4,5],[1,3,4],[2,6]]Output: [1,1,2,3,4,4,5,6]Explanation: The linked-lists are:[1->4->5,1->3->4,2->6]merging them into one sorted list:1->1->2->3->4->4->5->6 ...

Solved! Leetcode 1162: As Far from Land as Possible

source: https://leetcode.com/problems/as-far-from-land-as-possible/description/ As Far from Land as Possible Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the ...