- 博客(49)
- 资源 (1)
- 收藏
- 关注

原创 *223 Rectangle Area
只想到最简单的方法,把所有可能情况列出来,导致程序很繁琐。class Solution {public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int res = (C-A)*(D-B)+(G-E)*(H-F); A = max(A,E);
2015-11-14 20:48:38
184

原创 *27 Remove Element
做出来了,不过花的时间比较多,不熟练class Solution {public: int removeElement(vector& nums, int val) { int i = 0; int size = nums.size(); int j = size-1; int count = 0; wh
2015-11-14 20:11:30
212

原创 *13 Roman to Integer
没明白罗马数字的规律,只有可能左边一class Solution {public: int romanToInt(string s) { int res = 0; for(int i=0;i<s.size();++i) { int a = getNum(s[i]); int b = 0;
2015-11-14 20:07:33
242
转载 原生JavaScript事件详解
JQuery这种Write Less Do More的框架,用多了难免会对原生js眼高手低。 小菜其实不想写这篇博客,貌似很初级的样子,但是看到网络上连原生js事件绑定和解除都说不明白,还是决定科普一下了。 首先声明,小菜懂的也不是很多,只是把我的思路和大家分享一下。 DOM0事件模型 事件模型在不断发展,早期的事件模型称为DOM0级别。
2017-10-25 18:19:05
1796
转载 关于原生js的一些研究
callee和callerfunction inner(){ console.log(arguments.callee);//指向拥有这个arguments对象的函数,即inner() console.log(arguments.callee.caller);//这个属性保存着调用当前函数的函数的引用,即outer() console.log(inner.caller)
2017-10-25 10:16:32
191
转载 原生js的一些研究和总结(1)
数据类型基本类型值包括: undefined,null,Boolean,Number和String,这些类型分别在内存中占有固定的大小空间,它们的值保存在栈空间,我们通过按值来访问的。 引用类型包括:对象、数组、函数等。 对于引用类型的值,则必须在堆内存中为这个值分配空间。由于引用类型值的大小不固定(对象有很多属性和方法,而且还可以动态的添加属性和方法),因此不能把他们保存到栈
2017-10-25 09:47:08
206
原创 88 Merge Sorted Array
class Solution {public: void merge(vector& nums1, int m, vector& nums2, int n) { int i = m-1; int j = n-1; while(i>=0&&j>=0) { //这个if语句只是为了提高一点效率// if
2015-11-15 10:30:42
213
原创 190 Reverse Bits
class Solution {public: uint32_t reverseBits(uint32_t n) { uint32_t res = 0; int i = 0; while(i<32) { res<<=1; res |= (n&1); n>
2015-11-15 10:30:16
228
原创 36 Valid Sudoku
class Solution {public: bool isValidSudoku(vector>& board) { //每一行 for(int i=0;i<9;++i) { bool s[9]; for(int j=0;j<9;++j) s[j] = fa
2015-11-15 10:29:53
200
原创 19 Remove Nth Node From End of List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* re
2015-11-15 10:29:23
248
原创 20 Valid Parentheses
class Solution {public: bool isValid(string s) { int size = s.size(); stack res; for(int i=0;i<size;++i) { if(s[i]=='('||s[i]=='['||s[i]=='{')
2015-11-14 20:49:18
174
原创 219 Contains Duplicate II
class Solution {public: bool containsNearbyDuplicate(vector& nums, int k) { map res; int size = nums.size(); for(int i=0;i<size;++i) { if(res.find(nums
2015-11-14 20:47:53
157
原创 58 Length of Last Word
class Solution {public: int lengthOfLastWord(string s) { int size = s.size(); int j = size-1; while(j>=0&&s[j]==' ') --j; if(j==-1) return
2015-11-14 20:44:46
239
原创 111 Minimum Depth of Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
2015-11-14 20:42:00
172
原创 160 Intersection of Two Linked Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *ge
2015-11-14 20:41:33
155
原创 9 Palindrome Number
class Solution {public: bool isPalindrome(int x) { if(x<0) return false; int xx = x; int count = 0; while(xx!=0) { ++count
2015-11-14 20:40:58
247
原创 119 Pascal's Triangle II
class Solution {public: vector getRow(int rowIndex) { vector res; vector tmp; int i=0; while(i<=rowIndex) { tmp.clear(); tmp.push_b
2015-11-14 20:40:20
204
原创 102 Binary Tree Level Order Traversal
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
2015-11-14 20:39:46
210
原创 112 Path Sum
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
2015-11-14 20:39:01
221
原创 225 Implement Stack using Queues
class Stack {public: // Push element x onto stack. void push(int x) { q1.push(x); } // Removes the element on top of the stack. void pop() { while(q1.size()!=1)
2015-11-14 20:38:28
212
原创 172 Factorial Trailing Zeroes
class Solution {public: int trailingZeroes(int n) { int res = 0; while(n/5) { res += n/5; n/=5; } return res; }};
2015-11-14 20:37:47
225
原创 118 Pascal's Triangle
class Solution {public: vector> generate(int numRows) { vector> res; vector tmp; vector tmp1; int i=1; while(i<=numRows) { tmp1.clear()
2015-11-14 20:37:15
227
原创 66 Plus One
class Solution {public: vector plusOne(vector& digits) { vector res; int size = digits.size(); int add = 1; for(int i=size-1;i>=0;--i) { int tm
2015-11-14 20:36:50
182
原创 198 House Robber
class Solution {public: int rob(vector& nums) { int size = nums.size(); if(size==0) return 0; if(size==1) return nums[0]; int *res = new in
2015-11-14 20:36:18
283
原创 26 Remove Duplicates from Sorted Array
class Solution {public: int removeDuplicates(vector& nums) { int size = nums.size(); if(size<=1) return size; int i=0; int j=1; while(
2015-11-14 20:35:39
191
原创 107 Binary Tree Level Order Traversal II
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
2015-11-14 20:35:08
191
原创 101 Symmetric Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
2015-11-14 20:33:39
197
原创 231 Power of Two
class Solution {public: bool isPowerOfTwo(int n) { return (n&(n-1))==0&&n>0; }};
2015-11-14 20:32:55
216
原创 110 Balanced Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
2015-11-14 20:32:25
250
原创 21 Merge Two Sorted Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* me
2015-11-14 20:31:53
202
原创 232 Implement Queue using Stacks
class Queue {public: // Push element x to the back of queue. void push(int x) { s1.push(x); } // Removes the element from in front of queue. void pop(void) { if(s
2015-11-14 20:31:19
207
原创 202 Happy Number
class Solution {public: bool isHappy(int n) { if(n==1) return true; while(n!=0) { res.insert(n); vector tmp; while(n)
2015-11-14 20:30:43
148
原创 263 Ugly Number
class Solution {public: bool isUgly(int num) { if(num==0) return false; while(num%2==0) num/=2; while(num%3==0) num/=3; while(n
2015-11-14 20:30:11
209
原创 70 Climbing Stairs
class Solution {public: int climbStairs(int n) { int *res = new int[n+1]; for(int i=0;i<n+1;++i) res[i] = 0; res[1] = 1; res[2] = 2; for(int i=
2015-11-14 20:29:06
199
原创 83 Remove Duplicates from Sorted List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* de
2015-11-14 20:28:11
286
原创 206 Reverse Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* re
2015-11-14 20:27:22
234
原创 169 Majority Element
class Solution {public: int majorityElement(vector& nums) { int count = 0; int res; for(int i=0;i<nums.size();++i) { if(count==0) {
2015-11-14 20:25:28
156
原创 191 Number of 1 Bits
class Solution {public: int hammingWeight(uint32_t n) { int res = 0; while(n) { res++; n = n&(n-1); } return res; }};
2015-11-14 20:24:48
208
原创 235 Lowest Common Ancestor of a Binary Search Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
2015-11-14 20:24:11
290
原创 242 Valid Anagram
class Solution {public: bool isAnagram(string s, string t) { int res[256]; if(s.size()!=t.size()) return false; int size = s.size(); for(int i=0;i<256;
2015-11-14 20:20:11
190
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人