summaryrefslogtreecommitdiff
path: root/cpp/401.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-02-23 21:07:19 +0800
committercrupest <crupest@outlook.com>2021-02-23 21:07:19 +0800
commitd8f3b40085619cb680c8f227c65a1f5acc393223 (patch)
tree6a38e3a6c79276fc396259ef962d17236dbed569 /cpp/401.cpp
parentb0162802ad9723c678e495f29ca2f0fc0af2eff1 (diff)
downloadsolutions-d8f3b40085619cb680c8f227c65a1f5acc393223.tar.gz
solutions-d8f3b40085619cb680c8f227c65a1f5acc393223.tar.bz2
solutions-d8f3b40085619cb680c8f227c65a1f5acc393223.zip
Move leetcode solutions to subdir.
Diffstat (limited to 'cpp/401.cpp')
-rw-r--r--cpp/401.cpp57
1 files changed, 0 insertions, 57 deletions
diff --git a/cpp/401.cpp b/cpp/401.cpp
deleted file mode 100644
index 71147f4..0000000
--- a/cpp/401.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include <array>
-#include <string>
-#include <vector>
-
-using std::string;
-using std::vector;
-
-const std::array<int, 4> hour_digits{1, 2, 4, 8};
-const std::array<int, 6> minute_digits{1, 2, 4, 8, 16, 32};
-
-class Solution {
-public:
- template <int max, std::size_t size>
- void dfs(const std::array<int, size> &digits, int total_count, int rest_count,
- int start_index, int value, std::vector<int> &result) {
-
- if (value >= max)
- return;
-
- if (rest_count == 0) {
- result.push_back(value);
- return;
- }
-
- for (int i = start_index; i <= size - rest_count; i++) {
- dfs<max, size>(digits, total_count, rest_count - 1, i + 1,
- value + digits[i], result);
- }
- }
-
- vector<string> readBinaryWatch(int num) {
- vector<string> results;
-
- for (int i = (num > 6 ? num - 6 : 0); i <= (num > 4 ? 4 : num); i++) {
- std::vector<int> hours;
- std::vector<int> minutes;
- if (i == 0)
- hours = {0};
- else
- dfs<12>(hour_digits, i, i, 0, 0, hours);
- if (i == num)
- minutes = {0};
- else
- dfs<60>(minute_digits, num - i, num - i, 0, 0, minutes);
-
- for (auto hour : hours) {
- for (auto minute : minutes) {
- char buffer[6];
- sprintf(buffer, "%d:%02d", hour, minute);
- results.push_back(string(buffer));
- }
- }
- }
-
- return results;
- }
-};