- 博客(83)
- 资源 (6)
- 论坛 (2)
- 收藏
- 关注
原创 LeetCode C++ 744. Find Smallest Letter Greater Than Target【二分】简单
Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list that is larger than the given target.Letters also wrap around. For example, if the target is target = 'z'
2020-09-30 22:09:04
39
原创 LeetCode C++ 748. Shortest Completing Word【Hash Table】简单
Given a string licensePlate and an array of strings words , find the shortest completing word in words .A completing word is a word that contains all the letters in licensePlate . Ignore numbers and spaces in licensePlate , and treat letters as case insen
2020-09-30 21:41:58
28
原创 LeetCode C++ 704. Binary Search【二分】简单
Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, then return its index, otherwise return -1 .Example 1:Input: nums = [-1,0,3,5,9,12], target = 9Output:
2020-09-30 21:06:10
37
原创 LeetCode C++ 1009. Complement of Base 10 Integer【位运算】简单
Every non-negative integer N has a binary representation. For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on. Note that except for N = 0 , there are no leading zeroes in any binary representation.The complement of a
2020-09-29 14:29:48
29
原创 LeetCode C++ 476. Number Complement【位运算】简单
Given a positive integer num , output its complement number. The complement strategy is to flip the bits of its binary representation.Example 1:Input: num = 5Output: 2Explanation: The binary representation of 5 is 101 (no leading zero bits), and its co
2020-09-29 14:16:41
20
原创 LeetCode C++ 199. Binary Tree Right Side View【Tree/DFS/BFS】中等
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.Example:Input: [1,2,3,null,5,null,4]Output: [1, 3, 4]Explanation: 1 <--- / \2 3
2020-09-29 02:15:16
27
原创 LeetCode C++ 116. Populating Next Right Pointers in Each Node【Tree/DFS/BFS】中等
You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:struct Node { int val; Node *left; Node *right; Node *next;}Populate each next
2020-09-29 01:21:51
22
原创 LeetCode C++ 117. Populating Next Right Pointers in Each Node II【Tree/DFS/BFS】中等
Given a binary treestruct Node { int val; Node *left; Node *right; Node *next;}Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.Initially, all next pointers are
2020-09-29 01:20:01
19
原创 LeetCode C++ 968. Binary Tree Cameras【Tree/DFS】困难
Given 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 tree.Example 1:Input: [0,0,nul
2020-09-27 23:56:26
197
原创 LeetCode C++ 500. Keyboard Row【哈希表】简单
Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below.Example:Input: ["Hello", "Alaska", "Dad", "Peace"]Output: ["Alaska", "Dad"]Note:You may use one character
2020-09-27 08:47:41
18
原创 LeetCode C++ 961. N-Repeated Element in Size 2N Array【哈希表/数学】简单
In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times. Return the element repeated N times.Example 1:Input: [1,2,3,3]Output: 3 Example 2:Input: [2,1,2,5,3,2]Output: 2Example 3:Input: [5,
2020-09-26 23:14:36
24
原创 LeetCode C++ 701. Insert into a Binary Search Tree【二叉搜索树】中等
Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.Not
2020-09-26 17:03:25
40
原创 LeetCode C++ 700. Search in a Binary Search Tree【二叉搜索树】简单
Given the root node of a binary search tree BST and a value. You need to find the node in the BST that the node’s value equals the given value. Return the subtree rooted with that node. If such node doesn’t exist, you should return NULL .For example,Give
2020-09-26 16:23:19
21
原创 LeetCode C++ 680. Valid Palindrome II【String】简单
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.Example 1:Input: "aba"Output: TrueExample 2:Input: "abca"Output: TrueExplanation: You could delete the character 'c'.Note: The string wil
2020-09-26 16:09:50
22
原创 LeetCode C++ 575. Distribute Candies【Greedy】简单
You have n candies, the ith candy is of type candies[i] .You want to distribute the candies equally between a sister and a brother so that each of them gets n / 2 candies ( n is even). The sister loves to collect different types of candies, so you want to
2020-09-26 13:31:56
32
原创 LeetCode C++ 572. Subtree of Another Tree【Tree/DFS】简单
Given two non-empty binary trees s and t , check whether tree t has exactly the same structure and node values with a subtree of s . A subtree of s is a tree consists of a node in s and all of this node’s descendants. The tree s could also be considered as
2020-09-26 10:54:45
26
原创 LeetCode C++ 563. Binary Tree Tilt【Tree/DFS】简单
Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree node values. Null node has tilt 0 .The tilt of the whole
2020-09-26 10:25:15
25
原创 LeetCode C++ 504. Base 7【Math】简单
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note: The input will be in range of [-1e7, 1e7] .题意:给定一个整数,将其转化为 7 进制,并以字符串形式输出。思路进制转换。十进制到七进制的转换,很简单的题目,只是需要注意负数的处理。代码如
2020-09-26 00:57:47
16
原创 LeetCode C++ 106. Construct Binary Tree from Inorder and Postorder Traversal【Tree/分治】中等
Given inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.For example, giveninorder = [9,3,15,20,7]postorder = [9,15,7,20,3]Return the following binary tree: 3 / \
2020-09-26 00:50:48
37
原创 LeetCode C++ 105. Construct Binary Tree from Preorder and Inorder Traversal【Tree/分治】中等
Given preorder and inorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.For example, givenpreorder = [3,9,20,15,7]inorder = [9,3,15,20,7]Return the following binary tree: 3 / \
2020-09-26 00:45:59
26
原创 LeetCode C++ 506. Relative Ranks【Sort】简单
Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal" , "Silver Medal" and "Bronze Medal" .Example 1:Input: [5, 4, 3, 2, 1]Output: ["Gold Medal", "Silver Medal",
2020-09-25 22:23:12
24
原创 LeetCode C++ 507. Perfect Number【Math】简单
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n , write a function that returns true when it is a perfect number and false when it is not.Example:Input: 28Ou
2020-09-25 21:27:14
27
原创 LeetCode C++ 1591. Strange Printer II【模拟/拓扑排序】困难
There is a strange printer with the following two special requirements: On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle. Once the printer has used a.
2020-09-25 14:59:36
54
原创 LeetCode C++ 617. Merge Two Binary Trees【树/DFS/BFS】简单
Given 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, then sum n
2020-09-23 22:21:48
22
原创 LeetCode C++ 523. Continuous Subarray Sum【数学/前缀和/模运算】中等
Given a list of non-negative numbers and a target integer k , write a function to check if the array has a continuous subarray of size at least 2 that sums up to a multiple of k , that is, sums up to n*k where n is also an integer.Example 1:Input: [23,
2020-09-23 20:29:26
29
原创 LeetCode C++ 1590. Make Sum Divisible by P【数学/前缀和】中等
Given an array of positive integers nums , remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p . It is not allowed to remove the whole array.Return the length of the smallest subarray that you need t
2020-09-23 15:21:13
115
原创 LeetCode C++ 766. Toeplitz Matrix【Array】简单
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.Now given an M x N matrix, return True if and only if the matrix is Toeplitz .Example 1:Input:matrix = [ [1,2,3,4], [5,1,2,3], [9,5,1,2]]Output: TrueExpl
2020-09-22 19:42:52
18
原创 LeetCode C++ LCP 17. 速算机器人【String/Math】简单
小扣在秋日市集发现了一款速算机器人。店家对机器人说出两个数字(记作 x 和 y ),请小扣说出计算指令:"A" 运算:使 x = 2 * x + y ;"B" 运算:使 y = 2 * y + x 。在本次游戏中,店家说出的数字为 x = 1 和 y = 0 ,小扣说出的计算指令记作仅由大写字母 A 、B 组成的字符串 s ,字符串中字符的顺序表示计算顺序,请返回最终 x 与 y 的和为多少。示例 1:输入:s = "AB"输出:4解释:经过一次 A 运算后,x = 2, y = 0
2020-09-22 19:00:37
26
原创 LeetCode C++ 173. Binary Search Tree Iterator【二叉搜索树/栈/设计】中等
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST.Example:BSTIterator iterator = new BSTIterator(root);iterator.next();
2020-09-22 18:29:31
46
原创 LeetCode C++ 94. Binary Tree Inorder Traversal【二叉树/DFS】中等
Given the root of a binary tree, return the inorder traversal of its nodes’ values.Follow up: Recursive solution is trivial, could you do it iteratively?Example 1:Input: root = [1,null,2,3]Output: [1,3,2]Example 2:Input: root = []Output: []Examp
2020-09-22 16:50:02
19
原创 LeetCode C++ 144. Binary Tree Preorder Traversal【二叉树/DFS】中等
Given a binary tree, return the preorder traversal of its nodes’ values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,2,3]Follow up: Recursive solution is trivial, could you do it iteratively?题意:进行二叉树的先序遍历,返回元素序列。思路1先序递归遍历,很简
2020-09-22 16:49:35
16
原创 LeetCode C++ 145. Binary Tree Postorder Traversal【二叉树/DFS】中等
Given the root of a binary tree, return the postorder traversal of its nodes’ values.Follow up: Recursive solution is trivial, could you do it iteratively?Example 1:Input: root = [1,null,2,3]Output: [3,2,1]Example 2:Input: root = []Output: []Exa
2020-09-22 16:48:59
23
原创 LeetCode C++ 98. Validate Binary Search Tree【二叉搜索树/DFS】中等
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key.The right subtree of a node contains only nodes with keys grea
2020-09-22 15:27:54
15
原创 LeetCode C++ 979. Distribute Coins in Binary Tree【Tree/DFS】中等
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. (The move may be from parent to child, or from c
2020-09-22 15:02:49
29
原创 LeetCode C++ 538. Convert BST to Greater Tree【二叉搜索树】简单
Given 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.Example:Input: The root of a Binary Search Tree like this:
2020-09-22 01:44:09
60
原创 LeetCode C++ 1038. Binary Search Tree to Greater Sum Tree【二叉搜索树】中等
Given the root of a binary search tree with distinct values, modify it so that every node has a new value equal to the sum of the values of the original tree that are greater than or equal to node.val .As a reminder, a binary search tree is a tree that sa
2020-09-22 01:38:33
22
原创 LeetCode C++ 1589. Maximum Sum Obtained of Any Permutation【差分/前缀和/贪心/排序】中等
有一个整数数组 nums ,和一个查询数组 requests ,其中 requests[i] = [starti, endi] 。第 i 个查询求 nums[starti] + nums[starti + 1] + … + nums[endi - 1] + nums[endi] 的结果 ,starti 和 endi 数组索引都是 从 0 开始 的。你可以任意排列 nums 中的数字,请你返回所有查询结果之和的最大值。由于答案可能会很大,请你将它对 109 + 7 取余 后返回。示例 1:输入:nums
2020-09-21 15:40:23
44
原创 LeetCode C++ 1588. Sum of All Odd Length Subarrays【模拟】简单
给你一个正整数数组 arr ,请你计算所有可能的奇数长度子数组的和。子数组 定义为原数组中的一个连续子序列。请你返回 arr 中 所有奇数长度子数组的和 。示例 1:输入:arr = [1,4,2,5,3]输出:58解释:所有奇数长度子数组和它们的和为:[1] = 1[4] = 4[2] = 2[5] = 5[3] = 3[1,4,2] = 7[4,2,5] = 11[2,5,3] = 10[1,4,2,5,3] = 15我们将所有值求和得到 1 + 4 + 2 + 5 + 3
2020-09-21 15:11:55
81
原创 LeetCode C++ 78. Subsets【位操作/回溯】中等
Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]题意:给
2020-09-20 09:54:13
21
深入Python编程
2018-04-27
笨办法学Python
2018-04-22
CSDN电脑上读不了电子书?
发表于 2020-10-27 最后回复 2020-10-27
CSDN在电脑上读不了电子书?
发表于 2020-10-27 最后回复 2020-10-27
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人 TA的粉丝