随笔分类 -  leetcode

【leetcode】226-invert-binary-tree
摘要:problem 226-invert-binary-tree code solution1-DFS /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode 阅读全文

posted @ 2018-12-28 16:58 鹅要长大 阅读(169) 评论(0) 推荐(0)

[leetcode]225. Implement Stack using Queues
摘要:problem 225. Implement Stack using Queues code class MyStack { public: std::queue<int> myqueue; /** Initialize your data structure here. */ MyStack() 阅读全文

posted @ 2018-12-27 12:46 鹅要长大 阅读(118) 评论(0) 推荐(0)

219. Contains Duplicate II
摘要:problem 219. Contains Duplicate II solution1 class Solution { public: bool containsNearbyDuplicate(vector<int>& nums, int k) { for(int i=0; i<nums.siz 阅读全文

posted @ 2018-12-14 17:01 鹅要长大 阅读(126) 评论(0) 推荐(0)

217. Contains Duplicate
摘要:problem 217. Contains Duplicate solution1:暴力破解 class Solution { public: bool containsDuplicate(vector<int>& nums) { for(int i=0; i<nums.size(); i++) { 阅读全文

posted @ 2018-12-14 11:07 鹅要长大 阅读(143) 评论(0) 推荐(0)

206. Reverse Linked List
摘要:problem 206. Reverse Linked List code Iteration /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(i 阅读全文

posted @ 2018-12-14 10:33 鹅要长大 阅读(157) 评论(0) 推荐(0)

【leetcode】205-Isomorphic Strings
摘要:problem 205-Isomorphic Strings code 需要注意的 参考 1. Leetcode_Isomorphic Strings; 完 阅读全文

posted @ 2018-12-11 20:19 鹅要长大 阅读(157) 评论(0) 推荐(0)

204. Count Primes
摘要:problem 204. Count Primes 参考 1. CSDN大神; 2. CSDN; 3. Leetcode_CountPrimes; 完 2. CSDN; 3. Leetcode_CountPrimes; 完 阅读全文

posted @ 2018-12-10 22:45 鹅要长大 阅读(156) 评论(0) 推荐(0)

203. Remove Linked List Elements
摘要:203. Remove Linked List Elements code /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : va 阅读全文

posted @ 2018-12-09 19:59 鹅要长大 阅读(151) 评论(0) 推荐(0)

202. Happy Number
摘要:problem 202. Happy Number code 1. Leetcode_Happy Number; 2. GrandYang_cnblogs; 阅读全文

posted @ 2018-12-09 19:43 鹅要长大 阅读(164) 评论(0) 推荐(0)

198. House Robber
摘要:problem 198. House Robber solution1: code solution2: code class Solution { public: int rob(vector<int>& nums) { if(nums.size()==0) return 0; if(nums.s 阅读全文

posted @ 2018-12-09 13:42 鹅要长大 阅读(162) 评论(0) 推荐(0)

191. Number of 1 Bits
摘要:problem 191. Number of 1 Bits code solution2 依据二进制数据的性质,使用模板进行实现。 1. Leetcode_Number of 1 Bits; 阅读全文

posted @ 2018-12-09 13:30 鹅要长大 阅读(121) 评论(0) 推荐(0)

190. Reverse Bits
摘要:problem 190. Reverse Bits solution1: class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t res = 0; for(int i=0; i<32; i++) { res = res 阅读全文

posted @ 2018-12-08 19:58 鹅要长大 阅读(135) 评论(0) 推荐(0)

189. Rotate Array
摘要:problem 189. Rotate Array solution1: 暴力破解法(Time Limit Exceeded) class Solution { public: void rotate(vector<int>& nums, int k) { int tmp, pre; for(int 阅读全文

posted @ 2018-12-08 19:56 鹅要长大 阅读(115) 评论(0) 推荐(0)

172. Factorial Trailing Zeroes
摘要:problem 172. Factorial Trailing Zeroes 172. Factorial Trailing Zeroes code class Solution { public: int trailingZeroes(int n) { int ans = 0; while(n) 阅读全文

posted @ 2018-12-08 19:03 鹅要长大 阅读(124) 评论(0) 推荐(0)

171. Excel Sheet Column Number
摘要:problem 171. Excel Sheet Column Number sum( (s[i]-'A'+1)*pow(26, i) ) code 1. Leetcode_Excel Sheet Column Number; 阅读全文

posted @ 2018-12-08 19:01 鹅要长大 阅读(171) 评论(0) 推荐(0)

169. Majority Element
摘要:169. Majority Element HashMap code class Solution { public: int majorityElement(vector<int>& nums) { unordered_map<int, int> counts; for(int i=0; i<nu 阅读全文

posted @ 2018-12-07 13:45 鹅要长大 阅读(129) 评论(0) 推荐(0)

168. Excel Sheet Column Title
摘要:168. Excel Sheet Column Title code https://leetcode.com/problems/excel-sheet-column-title/description/ 阅读全文

posted @ 2018-12-07 09:35 鹅要长大 阅读(151) 评论(0) 推荐(0)

167. Two Sum II - Input array is sorted
摘要:167. Two Sum II - Input array is sorted code class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) { vector<int> res; int left 阅读全文

posted @ 2018-12-07 09:03 鹅要长大 阅读(162) 评论(0) 推荐(0)

160. Intersection of Two Linked Lists
摘要:160. Intersection of Two Linked Lists code /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) 阅读全文

posted @ 2018-12-05 18:04 鹅要长大 阅读(106) 评论(0) 推荐(0)

155. Min Stack
摘要:155. Min Stack code class MinStack { private: stack<int> s1; stack<int> s2; public: /** initialize your data structure here. */ MinStack() { } void pu 阅读全文

posted @ 2018-12-05 12:40 鹅要长大 阅读(128) 评论(0) 推荐(0)

导航