commit 648abcc77ab3d40dbf5a0052389bbf91b57223ae
parent c926f8287222d08199836081520b25db1c3c058c
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Wed, 19 Jul 2023 22:51:11 +0200
Random Problem
Diffstat:
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Problems/0179.cpp b/Problems/0179.cpp
@@ -0,0 +1,18 @@
+class Solution {
+public:
+ string largestNumber(const vector<int> &nums) {
+ const static auto cmp = [](const string &x, const string &y) {
+ return x + y > y + x;
+ };
+
+ vector<string> v(nums.size());
+ for (int i = 0; i < v.size(); i++) v[i] = to_string(nums[i]);
+
+ sort(v.begin(), v.end(), cmp);
+ if (v[0] == "0") return "0";
+
+ string res = "";
+ for (int i = 0; i < v.size(); i++) res += v[i];
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -169,6 +169,7 @@ for solving problems.
| 0169 | Easy | [Majority Element](Problems/0169.cpp) |
| 0171 | Easy | [Excel Sheet Column Number](Problems/0171.cpp) |
| 0173 | Medium | [Binary Search Tree Iterator](Problems/0173.cpp) |
+| 0179 | Medium | [Largest Number](Problems/0179.cpp) |
| 0187 | Medium | [Repeated DNA Sequences](Problems/0187.cpp) |
| 0189 | Medium | [Rotate Array](Problems/0189.cpp) |
| 0190 | Easy | [Reverse Bits](Problems/0190.cpp) |