自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(46)
  • 收藏
  • 关注

原创 LeetCode - 279. Perfect Squares

题目LeetCode - 279. Perfect Squares题目链接https://leetcode.com/problems/perfect-squares/参考博客https://www.cnblogs.com/grandyang/p/4800552.html解题思路本题解法参考上述博客。1. 解法一:四平方和定理根据四平方和定理知,任何正整数可表示成四个整数的平方和。...

2019-07-28 11:52:35 121

原创 LeetCode - 268. Missing Number

题目LeetCode - 268. Missing Number题目链接https://leetcode.com/problems/missing-number/参考博客解题思路解题源码class Solution {public: int missingNumber(vector<int>& nums) { sort(nums.begin(...

2019-07-25 23:13:27 90

原创 LeetCode - 242. Valid Anagram

题目LeetCode - 242. Valid Anagram题目链接https://leetcode.com/problems/valid-anagram/参考博客解题思路解题源码class Solution {public: bool isAnagram(string s, string t) { int a[26]; for (int i = ...

2019-07-25 23:04:08 84

原创 LeetCode - 228. Summary Ranges

题目LeetCode - 228. Summary Ranges题目链接https://leetcode.com/problems/summary-ranges/参考博客[1] https://blog.csdn.net/hlsdbd1990/article/details/46311137解题思路用一个容器将属于一个范围的数据存起来,然后统一转换。额外发现:STL容器中只有ve...

2019-07-23 21:36:36 117

原创 LeetCode - 231. Power of Two

题目LeetCode - 231. Power of Two题目链接https://leetcode.com/problems/power-of-two/参考博客https://leetcode.com/problems/power-of-two/discuss/340168/C%2B%2B-0ms-one-line-code解题思路本题考查位移运算,解法一的思路好想,但是注意位移运...

2019-07-23 20:26:51 97

原创 LeetCode - 230. Kth Smallest Element in a BST

题目LeetCode - 230. Kth Smallest Element in a BST题目链接https://leetcode.com/problems/kth-smallest-element-in-a-bst/参考博客解题思路解题源码/** * Definition for a binary tree node. * struct TreeNode { * ...

2019-07-22 23:03:25 116

原创 LeetCode - 215. Kth Largest Element in an Array

题目LeetCode - 215. Kth Largest Element in an Array题目链接https://leetcode.com/problems/kth-largest-element-in-an-array/参考博客解题思路这应该是LeetCode中碰到的最简单的题。解题源码class Solution {public: int findKthLar...

2019-07-21 09:58:42 108

原创 LeetCode - 209. Minimum Size Subarray Sum

题目LeetCode - 209. Minimum Size Subarray Sum题目链接https://leetcode.com/problems/minimum-size-subarray-sum/参考博客https://www.cnblogs.com/zjutlitao/p/3485545.html解题思路采用暴力解决,时间复杂度是O(n3)O(n^3)O(n3),这个基...

2019-07-21 09:58:11 90

原创 LeetCode - 208. Implement Trie (Prefix Tree)

题目LeetCode - 208. Implement Trie (Prefix Tree)题目链接https://leetcode.com/problems/implement-trie-prefix-tree/参考博客解题思路解题源码class Trie {public: /** Initialize your data structure here. */ s...

2019-07-21 09:57:27 134

原创 LeetCode - 205. Isomorphic Strings

题目LeetCode - 205. Isomorphic Strings题目链接https://leetcode.com/problems/isomorphic-strings/参考博客解题思路本题要求:若一个字符串将其中若干字符全部替换,能得到另一个字符串,则这两个字符串同构。解题:用map记录当前字符在之前出现(若出现过)的位置,即上一次的位置。注:此题记录上一次的位置加了1,...

2019-07-21 09:56:56 115

原创 LeetCode - 204. Count Primes

题目LeetCode - 204. Count Primes题目链接https://leetcode.com/problems/count-primes/参考博客https://www.cnblogs.com/grandyang/p/4462810.html解题思路自行设计的算法时间复杂度是n∗n\sqrt{n} * nn​∗n,但是运行超时,参考博客的算法复杂度分析知时间复杂度相同...

2019-07-21 09:56:23 109

原创 LeetCode - 203. Remove Linked List Elements

题目LeetCode - 203. Remove Linked List Elements题目链接https://leetcode.com/problems/remove-linked-list-elements/参考博客解题思路像链表删除节点这类题,头结点和尾节点摘除处理起来比较麻烦,这类可以借鉴以往参考的博客中的一个做法,给链表添加一个无效节点作为头结点(dummy),那么原有的头...

2019-07-19 22:04:57 100

原创 LeetCode - 202. Happy Number

题目LeetCode - 202. Happy Number题目链接https://leetcode.com/problems/happy-number/参考博客解题思路解题源码class Solution {public: vector<int> numsplit(int n){ vector<int> v; if (!n)...

2019-07-19 21:48:07 69

原创 LeetCode - 167. Two Sum II - Input array is sorted

题目LeetCode - 167. Two Sum II - Input array is sorted题目链接https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/参考博客解题思路此题考查Two Pointer.解题源码class Solution {public: vector<int&gt...

2019-07-18 23:02:35 71

原创 LeetCode - 144. Binary Tree Preorder Traversal

题目LeetCode - 144. Binary Tree Preorder Traversal题目链接https://leetcode.com/problems/binary-tree-preorder-traversal/参考博客https://blog.csdn.net/gatieme/article/details/51163010解题思路此图采用两种解法,递归和迭代。递归做...

2019-07-18 10:43:51 75

原创 LeetCode - 143. Reorder List

题目LeetCode - 143. Reorder List题目链接https://leetcode.com/problems/reorder-list/参考博客解题思路考察Two Pointer,先将原有链表每个节点的指针(i.e., 地址)存在向量中,然后从向量两头向中间靠拢,移动原链表节点的位置。解题源码/** * Definition for singly-linked ...

2019-07-18 09:52:09 86

原创 LeetCode - 137. Single Number II

题目LeetCode - 137. Single Number II题目链接https://leetcode.com/problems/single-number-ii/参考博客解题思路解题源码class Solution {public: int singleNumber(vector<int>& nums) { map<int...

2019-07-18 09:20:46 86

原创 LeetCode - 136. Single Number

题目LeetCode - 136. Single Number题目链接https://leetcode.com/problems/single-number/参考博客解题思路解题源码class Solution {public: int singleNumber(vector<int>& nums) { map<int, int&g...

2019-07-18 09:20:20 62

原创 LeetCode - 134. Gas Station

题目LeetCode - 134. Gas Station题目链接https://leetcode.com/problems/gas-station/参考博客解题思路简单题。解题源码class Solution {public: int canCompleteCircuit(vector<int>& gas, vector<int>&amp...

2019-07-18 09:19:40 106

原创 LeetCode - 131. Palindrome Partitioning

题目LeetCode - 131. Palindrome Partitioning题目链接https://leetcode.com/problems/palindrome-partitioning/参考博客https://www.cnblogs.com/grandyang/p/4270008.html解题思路参考博客。解题源码class Solution {public: ...

2019-07-18 09:19:13 85

原创 LeetCode - 142. Linked List Cycle II

题目LeetCode - 142. Linked List Cycle II题目链接https://leetcode.com/problems/linked-list-cycle-ii/参考博客解题思路解题源码/** * Definition for singly-linked list. * struct ListNode { * int val; * Li...

2019-07-17 23:44:07 77

原创 LeetCode - 141. Linked List Cycle

题目LeetCode - 141. Linked List Cycle题目链接https://leetcode.com/problems/linked-list-cycle/参考博客解题思路常规解题思路,Two pointer方法。解题源码/** * Definition for singly-linked list. * struct ListNode { * in...

2019-07-17 23:33:45 87

原创 LeetCode - 129. Sum Root to Leaf Numbers

题目LeetCode - 131. Palindrome Partitioning题目链接https://leetcode.com/problems/palindrome-partitioning/参考博客https://www.cnblogs.com/grandyang/p/4270008.html解题思路参考博客。解题源码class Solution {public: ...

2019-07-17 19:21:54 58

原创 LeetCode - 129. Sum Root to Leaf Numbers

题目LeetCode - 129. Sum Root to Leaf Numbers题目链接https://leetcode.com/problems/sum-root-to-leaf-numbers/参考博客解题思路解题源码/** * Definition for a binary tree node. * struct TreeNode { * int val; ...

2019-07-17 19:21:20 105

原创 LeetCode - 125. Valid Palindrome

题目LeetCode - 125. Valid Palindrome题目链接https://leetcode.com/problems/valid-palindrome/参考博客解题思路简单题。解题源码class Solution {public: bool isPalindrome(string s) { string ans, ans2; ...

2019-07-17 19:20:45 71

原创 LeetCode - 122. Best Time to Buy and Sell Stock II

题目LeetCode - 122. Best Time to Buy and Sell Stock II题目链接https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/参考博客https://www.cnblogs.com/grandyang/p/4280803.html解题思路一开始把思路想复杂了,参考博客即...

2019-07-17 19:20:15 74

原创 LeetCode - 121. Best Time to Buy and Sell Stock

题目LeetCode - 121. Best Time to Buy and Sell Stock题目链接https://leetcode.com/problems/best-time-to-buy-and-sell-stock/参考博客解题思路解题源码class Solution {public: int maxProfit(vector<int>& ...

2019-07-17 19:19:30 72

原创 LeetCode - 117. Populating Next Right Pointers in Each Node II

题目LeetCode - 117. Populating Next Right Pointers in Each Node II题目链接https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/参考博客解题思路此题是题116的变体,略过。解题源码/*// Definition for ...

2019-07-17 11:03:24 66

原创 LeetCode - 116. Populating Next Right Pointers in Each Node

题目LeetCode - 116. Populating Next Right Pointers in Each Node题目链接https://leetcode.com/problems/populating-next-right-pointers-in-each-node/参考博客[1] https://www.cnblogs.com/grandyang/p/4051326.htm...

2019-07-17 10:54:49 75

原创 114. Flatten Binary Tree to Linked List

题目Flatten Binary Tree to Linked List题目链接https://leetcode.com/problems/flatten-binary-tree-to-linked-list/参考博客https://www.cnblogs.com/grandyang/p/4293853.html解题思路解题源码/** * Definition for a b...

2019-07-17 10:53:55 52

原创 LeetCode - 113. Path Sum II

题目LeetCode - 113. Path Sum II题目链接https://leetcode.com/problems/path-sum-ii/参考博客解题思路带路径的深度优先遍历。解题源码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode...

2019-07-17 10:53:12 87

原创 LeetCode - 112. Path Sum

题目LeetCode - 112. Path Sum题目链接https://leetcode.com/problems/path-sum/参考博客解题思路深度优先遍历。解题源码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; *...

2019-07-17 10:52:35 71

原创 LeetCode - 111. Minimum Depth of Binary Tree

题目LeetCode - 111. Minimum Depth of Binary Tree题目链接https://leetcode.com/problems/minimum-depth-of-binary-tree/参考博客解题思路带层参数的深度优先遍历。解题源码/** * Definition for a binary tree node. * struct TreeNod...

2019-07-17 10:51:18 72

原创 LeetCode - 110. Balanced Binary Tree

题目LeetCode - 110. Balanced Binary Tree题目链接https://leetcode.com/problems/balanced-binary-tree/参考博客解题思路递归解题。解题源码/** * Definition for a binary tree node. * struct TreeNode { * int val; * ...

2019-07-16 19:53:32 68

原创 LeetCode - 109. Convert Sorted List to Binary Search Tree

题目LeetCode - 109. Convert Sorted List to Binary Search Tree题目链接https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/参考博客解题思路此题是题108的变体,略过。解题源码/** * Definition for singly-li...

2019-07-16 19:32:47 69

原创 LeetCode - 108. Convert Sorted Array to Binary Search Tree

题目LeetCode - 108. Convert Sorted Array to Binary Search Tree题目链接https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/参考博客解题思路此题属于基础题,递归解题即可。解题源码/** * Definition for a bina...

2019-07-16 19:22:49 91

原创 LeetCode - 107. Binary Tree Level Order Traversal II

题目LeetCode - 107. Binary Tree Level Order Traversal II题目链接https://leetcode.com/problems/binary-tree-level-order-traversal-ii/参考博客解题思路此题是题102的变体,略过。解题源码/** * Definition for a binary tree node....

2019-07-16 18:52:42 71

原创 LeetCode - 106. Construct Binary Tree from Inorder and Postorder Traversal

题目LeetCode - 106. Construct Binary Tree from Inorder and Postorder Traversal题目链接https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/参考博客解题思路解题思路可以参考105那题。解题...

2019-07-16 18:43:52 70

原创 LeetCode - 105. Construct Binary Tree from Preorder and Inorder Traversal

题目Construct Binary Tree from Preorder and Inorder Traversal题目链接https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/参考博客https://www.cnblogs.com/grandyang/p/42...

2019-07-16 17:11:37 109

原创 LeetCode - 103. Binary Tree Zigzag Level Order Traversal

题目LeetCode - 103. Binary Tree Zigzag Level Order Traversal题目链接https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/参考博客https://blog.csdn.net/whutshiliu/article/details/96142289...

2019-07-16 15:56:59 105

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除