leetcode 401. Binary Watch
2016-11-23 21:59
381 查看
class Solution { public: vector<string> readBinaryWatch(int num) { vector<string> res[11]; vector<string> ans[11]; vector<string> result; if(num > 10 || num < 0) return result; for(int i = 0;i <= 11; i++){ int j = i, c = 0; while(j){ if(j&1) c++; j/=2; } string x=""; j = i; do{ x = char('0'+j%10)+x; j/=10; }while(j>0); res[c].push_back(x); } for(int i = 0;i <= 59;i++){ int j = i, c = 0; while(j){ if(j&1)c++; j/=2; } string x=""; j = i; for(int k = 0;k < 2; k++){ x = char('0'+j%10)+x; j/=10; } ans[c].push_back(x); } for(int i = 0;i <= num; i++){ string x=""; for(int j = 0;j < res[i].size(); j++){ for(int k = 0;k < ans[num-i].size(); k++){ x = res[i][j]+":"+ans[num-i][k]; result.push_back(x); } } } return result; } };
相关文章推荐
- LeetCode-Backtracking-401. Binary Watch
- [leetcode: Python]401. Binary Watch
- 【LeetCode】401. Binary Watch
- [LeetCode]401. Binary Watch
- leetCode 401. Binary Watch
- LeetCode 401. Binary Watch
- Leetcode: 401. Binary Watch
- Leetcode-401. Binary Watch
- [LeetCode]401. Binary Watch &bitset的用法&to_string
- Leetcode 401. Binary Watch
- 位操作-leetcode 401. Binary Watch
- LeetCode-401. Binary Watch
- [leetcode]: 401. Binary Watch
- 【Leetcode】401. Binary Watch
- 401. Binary Watch
- 401. Binary Watch
- 401. Binary Watch
- LeetCode之路:401. Binary Watch
- 401. Binary Watch
- LeetCode Binary Watch