- 博客(30)
- 资源 (4)
- 收藏
- 关注
原创 117. Populating Next Right Pointers in Each Node II(Leetcode每日一题-2020.09.28)
占坑
2020-09-28 10:39:53 308
原创 235. Lowest Common Ancestor of a Binary Search Tree(Leetcode每日一题-2020.09.27)
占坑
2020-09-28 10:39:19 515 1
原创 113. Path Sum II(Leetcode每日一题-2020.09.26)
ProblemGiven a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.Note: A leaf is a node with no children.ExampleGiven the below binary tree and sum = 22,Return:Solution/** * Definition for a binary tree
2020-09-26 12:14:25 345
原创 106. Construct Binary Tree from Inorder and Postorder Traversal(Leetcode每日一题-2020.09.25)
ProblemGiven inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.ExampleFor example, giveninorder = [9,3,15,20,7]postorder = [9,15,7,20,3]Return the following binary tr
2020-09-25 20:26:53 164
原创 501. Find Mode in Binary Search Tree(Leetcode每日一题-2020.09.24)
ProblemGiven a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than or equal to the
2020-09-24 21:32:21 348
原创 617. Merge Two Binary Trees(Leetcode每日一题-2020.09.23)
ProblemGiven two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, th
2020-09-23 21:30:58 317
原创 968. Binary Tree Cameras(Leetcode每日一题-2020.09.22)--抄答案
ProblemBinary Tree CamerasGiven a binary tree, we install cameras on the nodes of the tree.Each camera at a node can monitor its parent, itself, and its immediate children.Calculate the minimum number of cameras needed to monitor all nodes of the tre
2020-09-22 22:52:56 517
原创 416. Partition Equal Subset Sum(Leetcode每日一题-2020.10.11)
ProblemGiven a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the array element will not exceed 100.The array size will not e
2020-09-21 20:59:15 399
原创 538. Convert BST to Greater Tree&1038. BST to Greater Sum Tree(Leetcode每日一题-2020.09.22)
ProblemGiven a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.ExampleSolution右->中->左 遍历/** * Definition fo
2020-09-21 19:48:18 289
原创 78. Subsets(Leetcode每日一题-2020.09.20)
ProblemGiven a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.ExampleInput: nums = [1,2,3]Output:[[3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]Solutioncla
2020-09-20 11:01:54 205
原创 404. Sum of Left Leaves(Leetcode每日一题-2020.09.19)
ProblemFind the sum of all left leaves in a given binary tree.ExampleSolution首先就是我们只求叶子节点之和(左孩子右孩子为空就可以判断是否为叶子节点),然后需要判断是否是左边的叶子节点,所以我们只需要判断每个节点左边节点是否为空,如果不为空是否为叶子节点,如果成立我们就返回这个左孩子的值再加上向右边孩子进行递归计算的值(右孩子中也有可能有左叶子节点)。/** * Definition for a binary tree
2020-09-19 10:49:58 398
原创 47. Permutations II(Leetcode每日一题-2020.09.18)
ProblemGiven a collection of numbers that might contain duplicates, return all possible unique permutations.ExampleInput: [1,1,2]Output:[[1,1,2],[1,2,1],[2,1,1]]Solutionclass Solution {public: vector<vector<int>> ret;
2020-09-18 20:34:01 401
原创 685. Redundant Connection II(Leetcode每日一题-2020.09.17)---抄答案
ProblemIn this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root node which has no parents.The gi
2020-09-17 21:39:16 290
原创 226. Invert Binary Tree(Leetcode每日一题-2020.09.16)
ProblemInvert a binary tree.ExampleSolution/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti
2020-09-16 20:54:24 368
原创 37. Sudoku Solver(Leetcode每日一题-2020.09.15)
ProblemWrite a program to solve a Sudoku puzzle by filling the empty cells.A sudoku solution must satisfy all of the following rules:Each of the digits 1-9 must occur exactly once in each row.Each of the digits 1-9 must occur exactly once in each colum
2020-09-15 21:28:16 803
原创 94. Binary Tree Inorder Traversal(Leetcode每日一题-2020.09.14)
ProblemGiven a binary tree, return the inorder traversal of its nodes’ values.ExampleSolution/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x),
2020-09-14 20:50:06 419
原创 79. Word Search(Leetcode每日一题-2020.09.13)
ProblemGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used
2020-09-13 21:50:25 593
原创 637. Average of Levels in Binary Tree(Leetcode每日一题-2020.09.12)
ProblemGiven a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Note:The range of node’s value is in the range of 32-bit signed integer.ExampleSolution/** * Definition for a binary tree node. * str
2020-09-13 21:47:45 307
原创 216. Combination Sum III(Leetcode每日一题-2020.09.11)
ProblemFind all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Note:All numbers will be positive integers.The solution set must not c
2020-09-11 20:21:01 206
原创 40. Combination Sum II(Leetcode每日一题-2020.09.10)
ProblemGiven a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidates may only be used once in the combination.Note:All
2020-09-10 19:39:01 147
原创 39. Combination Sum(Leetcode每日一题-2020.09.09)
ProblemGiven a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same repeated number may be chosen from candidates unlimited
2020-09-09 21:54:30 199
转载 gcc的-D和-U参数:宏的设置与取消
/* hello.c */#include <stdio.h>#ifdef YESchar* str = "Yes, this is a macro.";#elsechar* str = "No, there is no macro.";#endifint main(){ printf("%s\n", str); return 0;}使用-D传入宏YES来进行编译:recordus@LFS test # gcc -DYES -o helloyes he
2020-09-09 10:10:07 1168
原创 77. Combinations(Leetcode每日一题-2020.09.08)
ProblemGiven two integers n and k, return all possible combinations of k numbers out of 1 … n.You may return the answer in any order.Constraints:1 <= n <= 201 <= k <= nExample1Input: n = 4, k = 2Output:[[2,4],[3,4],[2,3],[1,2],
2020-09-08 21:04:26 162
原创 347. Top K Frequent Elements(Leetcode每日一题-2020.09.07)
ProblemGiven a non-empty array of integers, return the k most frequent elements.Note:You may assume k is always valid, 1 ≤ k ≤ number of unique elements.Your algorithm’s time complexity must be better than O(n log n), where n is the array’s size.It’s
2020-09-07 22:04:31 221
原创 107. Binary Tree Level Order Traversal II(Leetcode每日一题-2020.09.06)
ProblemGiven a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).ExampleGiven binary tree [3,9,20,null,null,15,7],return its bottom-up level order traversal as:So
2020-09-06 17:27:59 147
原创 60. Permutation Sequence(Leetcode每日一题-2020.09.05)
ProblemThe set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence for n = 3:“123”“132”“213”“231”“312”“321”Given n and k, return the kth permutation sequenc
2020-09-06 17:26:23 169
原创 257. Binary Tree Paths(Leetcode每日一题-2020.09.04)
ProblemGiven a binary tree, return all root-to-leaf paths.Note: A leaf is a node with no children.ExampleSolution/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * Tree
2020-09-04 20:28:48 96
原创 51. N-Queens(Leetcode每日一题-2020.09.03)
ProblemThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each solution contains a distinct board configuration
2020-09-03 21:16:57 215
原创 65. Valid Number&&剑指 Offer 20. 表示数值的字符串(Leetcode每日一题-2020.09.02)
Problem请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100"、“5e2”、"-123"、“3.1416”、"-1E-16"、“0123"都表示数值,但"12e”、“1a3.14”、“1.2.3”、"±5"及"12e+5.4"都不是。Solutionclass Solution {public: bool isNumber(string s) { int l = 0, r = s.size() - 1; //去掉首尾的空格
2020-09-02 21:49:49 161
原创 486. Predict the Winner(Leetcode每日一题-2020.09.01)
ProblemGiven an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for t
2020-09-01 22:12:50 180
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人