1 Random Problem
Diffstat:
2 files changed, 28 insertions(+), 0 deletions(-)
@@ -0,0 +1,27 @@
class Solution {
inline static string convert(int n) {
if (n < 10) return '0' + to_string(n);
return to_string(n);
}
public:
vector<string> readBinaryWatch(int turnedOn) const {
if (turnedOn == 0) return {"0:00"};
vector<string> res;
unsigned i = (1 << turnedOn) - 1, t;
while (i < (1 << 10)) {
const int hours = i >> 6, minutes = i & 0x3F;
if (hours < 12 && minutes < 60) {
res.push_back(to_string(hours) + ':' + convert(minutes));
}
const unsigned t = i | (i - 1);
i = (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(i) + 1));
}
return res;
}
};
@@ -313,6 +313,7 @@
for solving problems.
| 0394 | Medium | [Decode String](Problems/0394.cpp) |
| 0398 | Medium | [Random Pick Index](Problems/0398.cpp) |
| 0399 | Medium | [Evaluate Division](Problems/0399.cpp) |
| 0401 | Easy | [Binary Watch](Problems/0401.cpp) |
| 0402 | Medium | [Remove K Digits](Problems/0402.cpp) |
| 0403 | Hard | [Frog Jump](Problems/0403.cpp) |
| 0404 | Easy | [Sum of Left Leaves](Problems/0404.cpp) |