aboutsummaryrefslogtreecommitdiff
path: root/works
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-09-17 18:57:32 +0800
committercrupest <crupest@outlook.com>2020-09-17 18:57:32 +0800
commit358397d169e9d9f094504f2ad9976347a5931af5 (patch)
tree73632ac06e53cf2234c4572c66ec44605c16f0d0 /works
parentb998be33cf92366a15bb219af12442b3894f2c99 (diff)
downloadcrupest-358397d169e9d9f094504f2ad9976347a5931af5.tar.gz
crupest-358397d169e9d9f094504f2ad9976347a5931af5.tar.bz2
crupest-358397d169e9d9f094504f2ad9976347a5931af5.zip
import(solutions): Add problem 1370 .
Diffstat (limited to 'works')
-rw-r--r--works/solutions/cpp/1370.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/works/solutions/cpp/1370.cpp b/works/solutions/cpp/1370.cpp
new file mode 100644
index 0000000..9741d48
--- /dev/null
+++ b/works/solutions/cpp/1370.cpp
@@ -0,0 +1,45 @@
+#include <string>
+
+using std::string;
+
+class Solution
+{
+public:
+ string sortString(string s)
+ {
+ int count[26]{0};
+
+ for (auto c : s)
+ {
+ count[c - 'a']++;
+ }
+
+ int total_count = s.size();
+ string result;
+
+ while (total_count)
+ {
+ for (int i = 0; i < 26; i++)
+ {
+ if (count[i])
+ {
+ count[i]--;
+ total_count--;
+ result.push_back(i + 'a');
+ }
+ }
+
+ for (int i = 25; i >= 0; i--)
+ {
+ if (count[i])
+ {
+ count[i]--;
+ total_count--;
+ result.push_back(i + 'a');
+ }
+ }
+ }
+
+ return result;
+ }
+};