LeetCode
v_today_v
这个作者很懒,什么都没留下…
展开
-
Happy Number
bool isHappy(int n) { if(n return false; bool isIndatas(int*,int,int); int N=50; int* datas=(int*)malloc(N*sizeof(int)); datas[0]=n; int index=1; bool result=false; int m=n; int q=10; l原创 2015-04-26 09:59:55 · 240 阅读 · 0 评论 -
isIsomorphic
#include #include #include #include using std::set; using std::map; using std::string; bool isIsomorphic(string s, string t) { if(s.size()!=t.size()||s.size() return false; mapmap_s; setset原创 2015-05-07 18:08:23 · 313 阅读 · 0 评论 -
Number of 1 Bits
int hammingWeight(unsignedint n){ intcount=0; while(n){ count+=n&1; n>>=1; } returncount; }原创 2015-05-07 11:16:02 · 187 阅读 · 0 评论 -
Reverse Bits
uint32_t reverseBits(uint32_t n) { unsigned int re_n=0; int index=32; while(index){ re_n+=n&1; n>>=1; if(index!=1) re_n --index; } return re_n; }原创 2015-05-07 11:15:16 · 210 阅读 · 0 评论 -
Count Primes
int countPrimes(int n) { if(n return 0; int *nums=(int*)malloc(sizeof(int)*(n/2)); for(int i=0;i nums[i]=i*2+1; for(int i=3;i for(int j=i*3;j nums[j/2]=0; int count=0; for(int i=0;i if(原创 2015-05-06 20:01:50 · 204 阅读 · 0 评论 -
Rotate Array
void rotate(int* nums, int numsSize, int k) { void rotateSubStr(int* nums,int numsSize,int begin,int end); if(nums==NULL||numsSize return; k=k%numsSize; rotateSubStr(nums,numsSize,0,numsS原创 2015-05-09 19:38:42 · 227 阅读 · 0 评论 -
Reverse Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* reverseList(struct ListNode* head) { if(head==NULL)原创 2015-05-09 19:37:10 · 210 阅读 · 0 评论 -
Bitwise AND of Numbers Range
int rangeBitwiseAnd(int m, int n) { if(m>n) return 0; int exp=0; int re_n=n/2; while(re_n){ exp++; re_n/=2; } if(m return 0; if((m==2147483646)||(m==2147483647)) return m&n; int res=m原创 2015-05-09 19:35:59 · 244 阅读 · 0 评论 -
Remove Linked List Elements
struct ListNode* removeElements(struct ListNode* head, int val) { if(head==NULL){ return NULL; } struct ListNode* result=head; struct ListNode* Index=head; while(Index!=NULL&&Ind原创 2015-04-26 09:55:50 · 187 阅读 · 0 评论 -
House Robber
int max(int a,int b){ return a>b?a:b; } int rob(int* nums, int numsSize) { if(nums==NULL||numsSize return 0; if(numsSize==1) return *nums; int pre=nums[0]; int result=max(nums[0],nums[1])原创 2015-05-29 20:46:32 · 223 阅读 · 0 评论