摘要:problem 226-invert-binary-tree code solution1-DFS /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode
阅读全文
摘要:problem 225. Implement Stack using Queues code class MyStack { public: std::queue<int> myqueue; /** Initialize your data structure here. */ MyStack()
阅读全文
摘要:problem 219. Contains Duplicate II solution1 class Solution { public: bool containsNearbyDuplicate(vector<int>& nums, int k) { for(int i=0; i<nums.siz
阅读全文
摘要:problem 217. Contains Duplicate solution1:暴力破解 class Solution { public: bool containsDuplicate(vector<int>& nums) { for(int i=0; i<nums.size(); i++) {
阅读全文
摘要:problem 206. Reverse Linked List code Iteration /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(i
阅读全文
摘要:problem 205-Isomorphic Strings code 需要注意的 参考 1. Leetcode_Isomorphic Strings; 完
阅读全文
摘要:problem 204. Count Primes 参考 1. CSDN大神; 2. CSDN; 3. Leetcode_CountPrimes; 完 2. CSDN; 3. Leetcode_CountPrimes; 完
阅读全文
摘要:203. Remove Linked List Elements code /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : va
阅读全文
摘要:problem 202. Happy Number code 1. Leetcode_Happy Number; 2. GrandYang_cnblogs;
阅读全文
摘要: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
阅读全文
摘要:problem 191. Number of 1 Bits code solution2 依据二进制数据的性质,使用模板进行实现。 1. Leetcode_Number of 1 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
阅读全文
摘要:problem 189. Rotate Array solution1: 暴力破解法(Time Limit Exceeded) class Solution { public: void rotate(vector<int>& nums, int k) { int tmp, pre; for(int
阅读全文
摘要:problem 172. Factorial Trailing Zeroes 172. Factorial Trailing Zeroes code class Solution { public: int trailingZeroes(int n) { int ans = 0; while(n)
阅读全文
摘要:problem 171. Excel Sheet Column Number sum( (s[i]-'A'+1)*pow(26, i) ) code 1. Leetcode_Excel Sheet Column Number;
阅读全文
摘要:169. Majority Element HashMap code class Solution { public: int majorityElement(vector<int>& nums) { unordered_map<int, int> counts; for(int i=0; i<nu
阅读全文
摘要:168. Excel Sheet Column Title code https://leetcode.com/problems/excel-sheet-column-title/description/
阅读全文
摘要: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
阅读全文
摘要:160. Intersection of Two Linked Lists code /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x)
阅读全文
摘要:155. Min Stack code class MinStack { private: stack<int> s1; stack<int> s2; public: /** initialize your data structure here. */ MinStack() { } void pu
阅读全文