![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
cainiao_23333
这个作者很懒,什么都没留下…
展开
-
1319. Number of Operations to Make Network Connected
https://leetcode.com/problems/number-of-operations-to-make-network-connected/There arencomputers numbered from0ton-1connected byethernet cablesconnectionsforming a network whereconnections[i] = [a, b]represents a connection between computersa...原创 2020-10-22 20:21:58 · 93 阅读 · 0 评论 -
1584. Min Cost to Connect All Points [Medium]
https://leetcode.com/problems/min-cost-to-connect-all-points/You are given an arraypointsrepresenting integer coordinates of some points on a 2D-plane, wherepoints[i] = [xi, yi].The cost of connecting two points[xi, yi]and[xj, yj]is themanhatta...原创 2020-10-22 00:40:41 · 142 阅读 · 2 评论 -
665. Non-decreasing Array [Easy]
https://leetcode.com/problems/non-decreasing-array/Given an arraynumswithnintegers, your task is to check if it could become non-decreasing by modifyingat most1element.We define an array is non-decreasing ifnums[i] <= nums[i + 1]holds for e...原创 2020-10-04 17:22:41 · 121 阅读 · 0 评论 -
1367. Linked List in Binary Tree [Medium]
https://leetcode.com/problems/linked-list-in-binary-tree/Given a binary treerootand alinked list withheadas the first node.Return True if all the elements in the linked list starting from theheadcorrespond to somedownward pathconnected in the...原创 2020-10-04 16:38:35 · 117 阅读 · 0 评论 -
380. Insert Delete GetRandom O(1) [Medium]
https://leetcode.com/problems/insert-delete-getrandom-o1/Implement theRandomizedSetclass:bool insert(int val)Inserts an itemvalinto the set if not present. Returnstrueif the item was not present,falseotherwise. bool remove(int val)Removes an...原创 2020-10-04 04:49:52 · 132 阅读 · 0 评论 -
560. Subarray Sum Equals K [Medium]
https://leetcode.com/problems/subarray-sum-equals-k/Given an array of integers and an integerk, you need to find the total number of continuous subarrays whose sum equals tok.Example 1:Input:nums = [1,1,1], k = 2Output: 2Constraints:The leng..原创 2020-10-03 23:38:48 · 117 阅读 · 0 评论 -
830. Positions of Large Groups [Easy]
https://leetcode.com/problems/positions-of-large-groups/In a stringsof lowercase letters, these letters form consecutive groups of the same character.For example, a string likes = "abbxxxxzyy"has the groups"a","bb","xxxx","z", and"yy".A gro...原创 2020-10-03 22:24:12 · 84 阅读 · 0 评论 -
229. Majority Element II [Medium]
https://leetcode.com/problems/majority-element-ii/Given an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times.Follow-up:Could you solve the problemin linear time and in O(1) space ?Example 1:Input: nums = [3,2,3]Outp...原创 2020-10-03 01:38:26 · 70 阅读 · 0 评论 -
1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree [Medium]
https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/Given two binary treesoriginalandclonedand given a reference to a nodetargetin the original tree.Theclonedtree is acopy oftheoriginaltree.Ret...原创 2020-10-03 00:19:42 · 138 阅读 · 0 评论 -
1110. Delete Nodes And Return Forest [Medium]
https://leetcode.com/problems/delete-nodes-and-return-forest/submissions/Given therootof a binary tree, each node in the tree has a distinct value.After deletingall nodes with a value into_delete, we are left with a forest (adisjoint union of tree...原创 2020-10-02 18:50:39 · 136 阅读 · 0 评论 -
998. Maximum Binary Tree II [Medium]
https://leetcode.com/problems/maximum-binary-tree-ii/We are given therootnode of amaximum tree:a tree where every node has a value greater than any other value in its subtree.Just as in theprevious problem, the given treewas constructed from an l...原创 2020-10-01 23:23:37 · 60 阅读 · 0 评论 -
1145. Binary Tree Coloring Game [Medium]
https://leetcode.com/problems/binary-tree-coloring-game/Two players play a turn based game on a binary tree. We are giventherootof this binary tree, and the number of nodesnin the tree.nis odd, andeach node has a distinct value from1ton.In...原创 2020-10-01 22:06:02 · 93 阅读 · 0 评论 -
695. Max Area of Island [Medium]
https://leetcode.com/problems/max-area-of-island/Given a non-empty 2D arraygridof 0's and 1's, anislandis a group of1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded ...原创 2020-10-01 17:51:31 · 72 阅读 · 0 评论 -
971. Flip Binary Tree To Match Preorder Traversal [Medium]
https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal/Given a binary tree withNnodes, each node has a different value from{1, ..., N}.A node in this binary tree can beflippedby swapping the left child and the right child of th...原创 2020-10-01 17:22:21 · 116 阅读 · 0 评论 -
1123. Lowest Common Ancestor of Deepest Leaves [Medium]
https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves/Given a rooted binary tree, return the lowest common ancestor of its deepest leaves.Recall that:The node of a binary tree is aleafif and only if it has no children Thedepthof...原创 2020-10-01 14:34:30 · 101 阅读 · 0 评论 -
1325. Delete Leaves With a Given Value [Medium]
https://leetcode.com/problems/delete-leaves-with-a-given-value/Given a binary treerootand an integertarget, delete all theleaf nodeswith valuetarget.Notethat once you delete a leaf node with valuetarget,if it's parent node becomes a leaf node ...原创 2020-10-01 03:56:24 · 96 阅读 · 0 评论 -
979. Distribute Coins in Binary Tree [Medium]
979. Distribute Coins in Binary Tree [Medium]Given the root of a binary tree with N nodes, each node in the tree has node.val coins, and there are N coins total.In one move, we may choose two adjacent nodes and move one coin from one node to another. (T原创 2020-10-01 01:04:09 · 75 阅读 · 0 评论 -
289.Game of Life [Medium]
https://leetcode.com/problems/game-of-life/According to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”Given a board with m by n cells, each原创 2020-09-30 22:46:52 · 79 阅读 · 0 评论 -
287. Find the Duplicate Number [Medium]
https://leetcode.com/problems/find-the-duplicate-number/Given an array of integersnumscontainingn + 1integers where each integer is in the range[1, n]inclusive.There is onlyone duplicate numberinnums, returnthisduplicate number.Follow-ups:...原创 2020-09-30 00:15:15 · 110 阅读 · 0 评论 -
926. Flip String to Monotone Increasing [Medium]
A string of'0's and'1's ismonotone increasingif it consists of some number of'0's (possibly 0), followed by some number of'1's (also possibly 0.)We are given a stringSof'0's and'1's, and we may flip any'0'to a'1'or a'1'to a'0'.Return t...原创 2020-09-28 03:07:23 · 83 阅读 · 0 评论 -
485. Max Consecutive Ones [Easy]
https://leetcode.com/problems/max-consecutive-ones/Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s.原创 2020-09-28 01:56:51 · 100 阅读 · 0 评论 -
832. Flipping an Image [Easy]
https://leetcode.com/problems/flipping-an-image/Given a binary matrixA, we want to flip the image horizontally, then invert it, and return the resulting image.To flip an image horizontally means that each row of the image is reversed. For example, fl..原创 2020-09-28 01:35:54 · 65 阅读 · 0 评论 -
566. Reshape the Matrix [Easy]
https://leetcode.com/problems/reshape-the-matrix/In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dimensiona原创 2020-09-28 00:38:29 · 67 阅读 · 0 评论 -
1315. Sum of Nodes with Even-Valued Grandparent [Medium]
https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/Given a binary tree, return the sum of values of nodes with even-valued grandparent. (Agrandparentof a node is the parent of its parent, if it exists.)If there are no nodes with...原创 2020-09-27 23:51:56 · 79 阅读 · 0 评论 -
1305. All Elements in Two Binary Search Trees [Medium]
https://leetcode.com/problems/all-elements-in-two-binary-search-trees/Given two binary search treesroot1androot2.Return a list containingall the integersfromboth treessorted inascendingorder.Example 1:Input: root1 = [2,1,4], root2 = [1,...原创 2020-09-27 22:55:15 · 93 阅读 · 0 评论 -
766. Toeplitz Matrix [Easy]
https://leetcode.com/problems/toeplitz-matrix/A matrix isToeplitzif every diagonal from top-left to bottom-right has the same element.Now given anM x Nmatrix, returnTrueif and only if the matrix isToeplitz.Example 1:Input:matrix = [ [1,2...原创 2020-09-27 21:52:07 · 108 阅读 · 0 评论 -
561. Array Partition I [Medium]
https://leetcode.com/problems/array-partition-i/Given an array of2nintegers, your task is to group these integers intonpairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possibl...原创 2020-09-27 20:38:35 · 84 阅读 · 0 评论 -
1261. Find Elements in a Contaminated Binary Tree [Medium]
https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree/Given abinary tree with the following rules:root.val == 0 IftreeNode.val == xandtreeNode.left != null, thentreeNode.left.val == 2 * x + 1 IftreeNode.val == xandtreeNode...原创 2020-09-27 17:34:38 · 83 阅读 · 0 评论 -
1302. Deepest Leaves Sum [Medium]
https://leetcode.com/problems/deepest-leaves-sum/Given a binary tree, return the sum of values of its deepest leaves.Example 1:Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]Output: 15Constraints:The number of nodes in the tree is b原创 2020-09-27 16:00:47 · 133 阅读 · 0 评论 -
238. Product of Array Except Self [Medium]
https://leetcode.com/problems/product-of-array-except-self/Given an arraynumsofnintegers wheren> 1, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Example:Input: [1,2,3,4]Out...原创 2020-09-27 15:57:15 · 58 阅读 · 0 评论 -
228. Summary Ranges [Medium]
https://leetcode.com/problems/summary-ranges/Given a sorted integer array without duplicates, return the summary of its ranges.Example 1:Input: [0,1,2,4,5,7]Output: ["0->2","4->5","7"]Explanation: 0,1,2 form a continuous range;4,5 form a c.原创 2020-09-27 15:18:36 · 68 阅读 · 0 评论 -
216. Combination Sum III [Medium]
https://leetcode.com/problems/combination-sum-iii/Find all valid combinations ofknumbers that sum up tonsuch that the following conditions are true:Only numbers1through9are used. Each number is usedat most once.Returna list of all possible ...原创 2020-09-27 02:16:22 · 66 阅读 · 0 评论 -
958. Check Completeness of a Binary Tree [Medium]
Given a binary tree, determine if it is acomplete binary tree.Definition of a complete binary tree fromWikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as ..原创 2020-09-27 00:48:43 · 73 阅读 · 0 评论 -
919. Complete Binary Tree Inserter
https://leetcode.com/problems/complete-binary-tree-inserter/Acompletebinary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.Write a data structureCBTInserterthat ...原创 2020-09-26 01:26:04 · 93 阅读 · 0 评论 -
889. Construct Binary Tree from Preorder and Postorder Traversal [Medium]
https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/Return any binary tree that matches the given preorder and postorder traversals.Values in the traversalspreandpostare distinctpositive integers.Example 1:...原创 2020-09-26 00:01:03 · 61 阅读 · 0 评论 -
1104. Path In Zigzag Labelled Binary Tree [Medium]
https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree/In an infinite binary tree where every node has two children, the nodes are labelled in row order.In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to ri原创 2020-09-25 01:06:59 · 119 阅读 · 0 评论 -
865. Smallest Subtree with all the Deepest Nodes [Medium]
https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/Given therootof a binary tree, the depth of each node isthe shortest distance to the root.Returnthe smallest subtreesuch that it containsall the deepest nodesin the origin...原创 2020-09-24 23:22:02 · 76 阅读 · 0 评论 -
1448. Count Good Nodes in Binary Tree [Medium]
https://leetcode.com/problems/count-good-nodes-in-binary-tree/Given a binary treeroot, a nodeXin the tree is namedgoodif in the path from root toXthere are no nodes with a valuegreater thanX.Return the number ofgoodnodes in the binary tree....原创 2020-09-24 00:40:37 · 125 阅读 · 0 评论 -
863. All Nodes Distance K in Binary Tree [Medium]
https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/We are given a binary tree (with root noderoot), atargetnode, and an integer valueK.Return a list of the values of allnodes that have a distanceKfrom thetargetnode. The answer ...原创 2020-09-23 23:31:01 · 70 阅读 · 0 评论 -
834. Sum of Distances in Tree [Hard]
https://leetcode.com/problems/sum-of-distances-in-tree/An undirected, connectedtree withNnodes labelled0...N-1andN-1edgesaregiven.Theith edge connects nodesedges[i][0]andedges[i][1]together.Return a listans, whereans[i]is the sum of ...原创 2020-09-23 00:27:40 · 99 阅读 · 0 评论