06 2015 档案

Intersection of Two Linked Lists
摘要:1 class Solution { 2 public: 3 ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { 4 int la=0,lb=0; 5 ListNode* pt=... 阅读全文

posted @ 2015-06-14 22:37 varcom 阅读(124) 评论(0) 推荐(0)

Compare Version Numbers
摘要:1 typedef struct Version 2 { 3 vector vec; 4 }Version; 5 int cmp(Version a,Version b) 6 { 7 int i; 8 int la=a.vec.size(),lb=b.vec.size();... 阅读全文

posted @ 2015-06-11 13:55 varcom 阅读(148) 评论(0) 推荐(0)

Factorial Trailing Zeroes
摘要:1 class Solution { 2 public: 3 int trailingZeroes(int n) { 4 int ans=0; 5 while(n) 6 { 7 ans+=n/5; 8 ... 阅读全文

posted @ 2015-06-11 10:57 varcom 阅读(113) 评论(0) 推荐(0)

Excel Sheet Column Number
摘要:1 class Solution { 2 public: 3 int titleToNumber(string s) { 4 int n=s.size(),i; 5 int ans=0; 6 for(i=0;i<n;i++) 7 ... 阅读全文

posted @ 2015-06-10 20:56 varcom 阅读(135) 评论(0) 推荐(0)

Majority Element
摘要:1 class Solution { 2 public: 3 int majorityElement(vector& nums) { 4 int n=nums.size(),i; 5 int m=nums[0]; 6 int cnt=1; 7... 阅读全文

posted @ 2015-06-10 20:23 varcom 阅读(152) 评论(0) 推荐(0)

Excel Sheet Column Title
摘要:1 class Solution { 2 public: 3 string convertToTitle(int n) { 4 string ans="",cur; 5 while(n) 6 { 7 n--; 8 ... 阅读全文

posted @ 2015-06-10 19:42 varcom 阅读(111) 评论(0) 推荐(0)

Rotate Array
摘要:1 class Solution { 2 public: 3 void rotate(vector& nums, int k) { 4 int n=nums.size(); 5 k%=n; 6 if(k==0) 7 ... 阅读全文

posted @ 2015-06-10 15:32 varcom 阅读(160) 评论(0) 推荐(0)

Reverse Bits
摘要:1 class Solution { 2 public: 3 uint32_t reverseBits(uint32_t n) { 4 uint32_t ans=0; 5 int t=0; 6 while(n) 7 { 8 ... 阅读全文

posted @ 2015-06-10 13:58 varcom 阅读(130) 评论(0) 推荐(0)

Number of 1 Bits
摘要:1 typedef unsigned int uint32_t; 2 class Solution { 3 public: 4 int hammingWeight(uint32_t n) { 5 int tot=0; 6 while(n) 7 ... 阅读全文

posted @ 2015-06-09 22:46 varcom 阅读(147) 评论(0) 推荐(0)

House Robber
摘要:1 int dp[1000000]; 2 class Solution { 3 public: 4 int rob(vector& nums) { 5 int i,n=nums.size(); 6 if(n==0) 7 return ... 阅读全文

posted @ 2015-06-09 22:12 varcom 阅读(119) 评论(0) 推荐(0)

Happy Number
摘要:1 class Solution { 2 public: 3 bool isHappy(int n) { 4 int dig[1000],cnt,ans; 5 memset(dig,0,sizeof(dig)); 6 while(1) 7 ... 阅读全文

posted @ 2015-06-09 20:05 varcom 阅读(161) 评论(0) 推荐(0)

Remove Linked List Elements
摘要:1 class Solution { 2 public: 3 ListNode* removeElements(ListNode* head, int val) { 4 ListNode*cur,*nxt,*pre=head; 5 if(head==NULL... 阅读全文

posted @ 2015-06-09 19:27 varcom 阅读(125) 评论(0) 推荐(0)

Count Primes
摘要:1 int ary[1500005]; 2 class Solution { 3 public: 4 int countPrimes(int n) { 5 int i,j; 6 memset(ary,0,sizeof(ary)); 7 int... 阅读全文

posted @ 2015-06-09 11:20 varcom 阅读(124) 评论(0) 推荐(0)

Isomorphic Strings
摘要:1 class Solution { 2 public: 3 bool isIsomorphic(string s, string t) { 4 map mp; 5 int sl=s.size(),st=t.size(); 6 if(sl!=... 阅读全文

posted @ 2015-06-08 10:16 varcom 阅读(123) 评论(0) 推荐(0)

Reverse Linked List
摘要:1 class Solution { 2 public: 3 ListNode* reverseList(ListNode* head) { 4 if(head==NULL) 5 return head; 6 ListNode* pr... 阅读全文

posted @ 2015-06-07 20:48 varcom 阅读(175) 评论(0) 推荐(0)

Contains Duplicate
摘要:1 class Solution { 2 public: 3 bool containsDuplicate(vector& nums) { 4 int n=nums.size(); 5 if(n==0) 6 return 0; 7 ... 阅读全文

posted @ 2015-06-07 10:13 varcom 阅读(110) 评论(0) 推荐(0)

Contains Duplicate II
摘要:1 struct Rec 2 { 3 int dig, ind; 4 }; 5 bool cmp(struct Rec a,struct Rec b) 6 { 7 if(a.dig!=b.dig) 8 return a.dig& nums, int k) {14 ... 阅读全文

posted @ 2015-06-06 18:37 varcom 阅读(175) 评论(0) 推荐(0)

Longest Common Prefix
摘要:1 class Solution { 2 public: 3 string longestCommonPrefix(vector& strs) { 4 if(strs.empty()) 5 return ""; 6 vector::i... 阅读全文

posted @ 2015-06-06 17:27 varcom 阅读(126) 评论(0) 推荐(0)

Roman to Integer
摘要:1 class Solution { 2 public: 3 int romanToInt(string s) { 4 int i,len=s.size(); 5 int dig[20]; 6 for(i=0;i<len;i++) 7 ... 阅读全文

posted @ 2015-06-06 11:38 varcom 阅读(120) 评论(0) 推荐(0)

Palindrome Number
摘要:class Solution {public: bool isPalindrome(int x) { long long int ans=0; int y=x; while(y) { ans=ans*10+y%10;... 阅读全文

posted @ 2015-06-05 22:26 varcom 阅读(154) 评论(0) 推荐(0)

String to Integer (atoi)
摘要:1 int max_value=2147483647; 2 int min_value=-2147483648; 3 class Solution { 4 public: 5 int myAtoi(string str) { 6 long long int ans=0; 7... 阅读全文

posted @ 2015-06-05 21:44 varcom 阅读(172) 评论(0) 推荐(0)

Reverse Integer
摘要:1 typedef long long lld; 2 lld mn=-((lld)1mx||ansmx||ans<mn)14 ans=0;15 return (int)ans;16 }17 };View Code 阅读全文

posted @ 2015-06-05 15:41 varcom 阅读(129) 评论(0) 推荐(0)

ZigZag Conversion
摘要:1 class Solution { 2 public: 3 string convert(string s, int numRows) { 4 if(numRows==1) 5 return s; 6 int i,j,gap=num... 阅读全文

posted @ 2015-06-03 22:18 varcom 阅读(171) 评论(0) 推荐(0)