1 Star 0 Fork 0

xiangxiang/LeetCode-NOTES

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
solution.cpp 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
默然 提交于 7年前 . Add 906,917-919,949-952
class Solution {
public:
string largestTimeFromDigits(vector<int>& A) {
vector<bool> used(4,false);
vector<int> result;
for(int i=0;i<A.size();i++){
if(A[i]<0 || A[i]>2)
continue;
int t1 = A[i];
used[i] = true;
for(int j=0;j<A.size();j++){
if(used[j] || (t1==2 && (A[j]>3 || A[j]<0) ) )
continue;
int t2 = t1*10 + A[j];
used[j] = true;
for(int k=0;k<A.size();k++){
if(used[k] || A[k]>5 || A[k]<0)
continue;
int t3 = t2*10 + A[k];
used[k] = true;
for(int y=0;y<A.size();y++){
if(used[y])
continue;
result.push_back(t3*10+A[y]);
// cout<<t3*10+A[y]<<endl;
}
used[k] = false;
}
used[j] = false;
}
used[i] = false;
}
if(result.empty())
return "";
vector<int>::iterator it = max_element(result.begin(), result.end());
string r = to_string(*it);
if(r.size()<4)
r = string(4-r.size(),'0') + r;
return r.substr(0,2) + ":" + r.substr(2);
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiangxiang920/LeetCode-NOTES.git
git@gitee.com:xiangxiang920/LeetCode-NOTES.git
xiangxiang920
LeetCode-NOTES
LeetCode-NOTES
master

搜索帮助