LeetCode 2015.7.8 128,171,172,189,202,203,119
来源:互联网 发布:中国网络域名注册 编辑:程序博客网 时间:2024/06/06 14:19
168 Excel Sheet Column Titleclass Solution {public: string convertToTitle(int n) { int tmp=n; string ans; ans.clear(); char chara[30]; for(int i=1;i<=25;i++) chara[i]='A'+i-1; chara[0]='Z'; if (n<=26) { ans.push_back(chara[n % 26]); return ans; } while (tmp!=0) { int res = tmp % 26; tmp = tmp / 26; if (res==0) tmp--; ans.push_back(chara[res]); } int len=ans.size()-1; string finalans; finalans.clear(); for(int i=len;i>=0;i--) finalans.push_back(ans[i]); return finalans; }};171 Excel Sheet Column Numberclass Solution {public: int titleToNumber(string s) { int len=s.size()-1; int sum=0,count=1; for(int i=len;i>=0;i--) { sum+=(s[i]-'A'+1)*count; count*=26; } return sum; }};172 Factorial Trailing Zeroesclass Solution {public: int trailingZeroes(int n) { int sum=0; while (n/5>0) { n/=5; sum+=n; } return sum; }};189 Rotate Arrayclass Solution {public: void rotate(vector<int>& nums, int k) { int len = nums.size(); if (k==0) return; int rotatek; rotatek=k%len; if (rotatek==0) return ; vector<int> tmp; tmp.clear(); for(int i=len-rotatek;i<len;i++) tmp.push_back(nums[i]); for(int i=0;i<len-rotatek;i++) tmp.push_back(nums[i]); for(int i=0;i<len;i++) nums[i]=tmp[i]; }};202 Happy Numberclass Solution {public: bool isHappy(int n) { set<int> appear; appear.clear(); int num=n; for(;;) { //cout<<num<<endl; if (num==1) return true; int sum=0; appear.insert(num); while (num!=0) { int tmp=num%10; sum+=tmp*tmp; num/=10; } if (appear.find(sum)!=appear.end()) return false; else { appear.insert(sum); num=sum; } } }};203 Remove Linked List Elementsclass Solution {public: ListNode* removeElements(ListNode* head, int val) { ListNode tmp(0); ListNode* p=&tmp; ListNode* q; p->next=head; head=p; q=head; p=p->next; while(p!=NULL) { if (p->val==val) { q->next=p->next; p=q->next; } else { q=p; p=p->next; } } return head->next; }};119 Pascal's Triangle IIclass Solution {public: vector<int> getRow(int rowIndex) { vector<int> tr[2]; int flag=0; int i=0; tr[flag].push_back(1); for(i=1;i<=rowIndex;i++) { int tmpflag=1-flag; tr[tmpflag].clear(); tr[tmpflag].push_back(1); for(vector<int>::iterator j=tr[flag].begin();j!=tr[flag].end()-1;j++) { tr[tmpflag].push_back((*j)+(*(j+1))); } tr[tmpflag].push_back(1); flag=tmpflag; } return tr[flag]; }};
0 0
- LeetCode 2015.7.8 128,171,172,189,202,203,119
- LEETCODE 172
- Leetcode 172
- LEETCODE 203
- LEETCODE 189
- leetcode 189
- LeetCode 189
- LEETCODE 171
- Leetcode 171
- leetcode 171
- LEETCODE 119
- leetcode 119
- leetcode 119
- LeetCode 202
- Leetcode 202
- LEETCODE 202
- Leetcode 202
- leetcode 202
- Uva 673 2015.6.7
- Uva 10050 2015.6.7
- view文档的分栏
- LeetCode 2015.7.7 205,206,217,219,223,228,231,111,112
- hdu1248 寒冰王座(完全背包)
- LeetCode 2015.7.8 128,171,172,189,202,203,119
- bestcoder#71
- 一致性Hash算法
- 在MFC类中各种类的指针的获取和应用
- LeetCode 2015.7.9 66,67,70,83,88,100
- 杭电1059Windows Message Queue
- 2015年终总结和2016年的计划
- poj1741 Tree
- iOS 获取项目文件路径