- 博客(13)
- 收藏
- 关注
原创 happy num
例如Example: 19 is a happy number12 + 92 = 8282 + 22 = 6862 + 82 = 10012 + 02 + 02 = 1两种方法,迭代和while计算出现重复,则不是class Solution {public: unordered_mapresult; bool isHappy
2015-12-11 17:33:50
138
原创 isUglyNUM
class Solution {public: bool isUgly(int num) { while(num>=2){ if(num%2==0)num=num/2; else if(num%3==0)num=num/3; else if(num%5==0)num=num/5; else return fa
2015-12-09 14:40:14
167
原创 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: Li
2015-12-08 21:05:48
150
原创 climbStairs
int climbStairs(int n) { /* int res=0; if(n%2==0) { for(int i=n/2;i { res+=combinatorial_num(i,n-i); }
2015-11-30 18:39:21
187
原创 Roman to Integer
class Solution {public: int char_to_num(char a){switch (a){case 'M':return 1000;case 'D':return 500;case 'C':return 100;case 'L':return 50;case 'X':return 10;case 'V
2015-11-29 15:32:42
163
原创 Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element
2015-11-24 21:55:24
139
原创 Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 class So
2015-11-24 20:56:22
118
原创 isAnagram
class Solution { public: bool isAnagram(string s, string t) { /* std::sort(s.begin(),s.end()); std::sort(t.begin(),t.end()); if (s==t) {
2015-11-23 22:18:18
251
原创 Contains Duplicate
bool containDuplicate(vector& nums) { if(nums.size()==0) return false; else{ int i=0; int j=0; vectorflag(nums.size(),0); //int flag[nums.size(
2015-11-23 21:16:10
109
原创 Invert 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) {} * };
2015-11-23 21:15:10
101
原创 Same Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };
2015-11-23 20:59:15
89
原创 Maximum 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) {} * };
2015-11-23 20:43:55
136
原创 Nim_Game
class Solution {public: bool canWinNim(int n) { return n%4!=0; }};
2015-11-23 20:37:33
138
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人