- 博客(19)
- 收藏
- 关注
原创 90. Subsets II
90. Subsets IIDescriptionIdeaCodeDescriptionGiven an integer array nums that may contain duplicates, return all possible subsets (the power set).The solution set must not contain duplicate subsets. Return the solution in any order.Idea这一题和subsets 一样但是
2022-05-07 14:28:24 124
原创 78. Subsets
78. SubsetsDescriptionIdeaCodeDescriptionGiven an integer array nums of unique elements, return all possible subsets (the power set).The solution set must not contain duplicate subsets. Return the solution in any order.Idea经典dfs问题, 因为nums里的值是unique的,而
2022-05-07 07:47:05 110
原创 272. Closest Binary Search Tree Value II
272. Closest Binary Search Tree Value IIDescriptionIdeaCodebrute-forceDFSsearch on treeNotesDescriptionGiven the root of a binary search tree, a target value, and an integer k, return the k values in the BST that are closest to the target. You may return
2022-05-01 08:34:11 132
原创 98. Validate Binary Search Tree
98. Validate Binary Search TreeDescriptionIdeaCodecode 1code 2NotesDescriptionGiven the root of a binary tree, determine if it is a valid binary search tree (BST).A valid BST is defined as follows:The left subtree of a node contains only nodes with key
2022-04-27 14:17:49 550
原创 236. Lowest Common Ancestor of a Binary Tree
236. Lowest Common Ancestor of a Binary TreeDescriptionIdeaCodeNotesDescriptionGiven a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defi
2022-04-26 14:44:25 179
原创 1586. Binary Search Tree Iterator II
1586. Binary Search Tree Iterator IIDescriptionIdeaCodeNotesDescriptionImplement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):BSTIterator(TreeNode root) Initializes an object of the BSTItera
2022-04-22 14:18:11 207
原创 230. Kth Smallest Element in a BST
230. Kth Smallest Element in a BSTDescriptionThoughtsCodeinorder traversalstackDescriptionGiven the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.ThoughtsWe can simp
2022-04-14 14:33:13 104
原创 Lintcode 573 · Build Post Office
Lintcode 573 · Build Post OfficeDescriptionNoteCodeDescriptionGiven a 2D grid, each cell is either a wall 2, an house 1 or empty 0 (the number zero, one, two), find a place to build a post office so that the sum of the distance from the post office to al
2022-03-21 13:33:58 82
原创 Connected Component in Undirected Graph
Connected Component in Undirected GraphDescriptionSimilar problemCodeDescriptionFind connected component in undirected graph.Each node in the graph contains a label and a list of its neighbors.(A connected component of an undirected graph is a subgraph
2022-03-10 15:27:25 150
原创 Graph Valid Tree
Graph Valid TreeDescriptionIdeaCodeDescriptionGiven n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.IdeaWe can simply use BFS but it’s imp
2022-03-10 14:58:47 380
原创 207. Course Schedule
207. Course ScheduleDescriptionThoughtsCodesNotesDescriptionThere are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take co
2022-02-16 14:03:41 139
原创 200. Number of Islands
200. Number of IslandsDescriptionAlgorithmExceptionsCodeTipsComplexityDescriptionGiven an m x n 2D binary grid grid which represents a map of '1’s (land) and '0’s (water), return the number of islands.An island is surrounded by water and is formed by co
2022-02-14 14:28:26 142
原创 102. Binary Tree Level Order Traversal
102. Binary Tree Level Order TraversalDescriptionExplainationCodesingle queue2 listsdummy nodeDescriptionGiven the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level).ExplainationA cl
2022-02-02 14:56:54 325
原创 658. Find K Closest Elements
658. Find K Closest ElementsDescriptionThoughtsCodeleverage a regular binary search templatea smart binary search solutionSummaryDescriptionGiven a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The resul
2022-01-19 15:11:24 233
原创 702. Search in a Sorted Array of Unknown Size
702. Search in a Sorted Array of Unknown SizeDescriptionThoughtsCodeSummaryDescriptionGiven a big sorted array with non-negative integers sorted by non-decreasing order. The array is so big so that you can not get the length of the whole array directly,
2022-01-18 15:31:45 180
原创 852. Peak Index in a Mountain Array
852. Peak Index in a Mountain ArrayDescriptionThoughtsExceptionsPython CodeBrute-forceWhile-loop Binary SearchRecursive Binary SearchSummaryDescriptionLet’s call an array arr a mountain if the following properties hold:arr.length >= 3There exists s
2022-01-18 14:09:14 787
原创 34. Find First and Last Position of Element in Sorted Array
34. Find First and Last Position of Element in Sorted ArrayDescriptionExceptionsPython CodeDescriptionGiven an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.If target is not found in
2022-01-18 08:31:53 809
原创 215. Kth Largest Element in an Array
215. Kth Largest Element in an ArrayProblem Description:ThoughtsAny exception or extreme cases?Python CodeEasy to make mistakeProblem Description:Given an integer array nums and an integer k, return the kth largest element in the array.Note that it is
2022-01-16 14:32:03 98
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人