Skip to content

Commit 591a473

Browse files
refactor 1370
1 parent 58a106b commit 591a473

File tree

1 file changed

+0
-44
lines changed

1 file changed

+0
-44
lines changed

src/main/java/com/fishercoder/solutions/_1370.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,5 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 1370. Increasing Decreasing String
5-
*
6-
* Given a string s. You should re-order the string using the following algorithm:
7-
* Pick the smallest character from s and append it to the result.
8-
* Pick the smallest character from s which is greater than the last appended character to the result and append it.
9-
* Repeat step 2 until you cannot pick more characters.
10-
* Pick the largest character from s and append it to the result.
11-
* Pick the largest character from s which is smaller than the last appended character to the result and append it.
12-
* Repeat step 5 until you cannot pick more characters.
13-
* Repeat the steps from 1 to 6 until you pick all characters from s.
14-
* In each step, If the smallest or the largest character appears more than once you can choose any occurrence and append it to the result.
15-
* Return the result string after sorting s with this algorithm.
16-
*
17-
* Example 1:
18-
* Input: s = "aaaabbbbcccc"
19-
* Output: "abccbaabccba"
20-
* Explanation: After steps 1, 2 and 3 of the first iteration, result = "abc"
21-
* After steps 4, 5 and 6 of the first iteration, result = "abccba"
22-
* First iteration is done. Now s = "aabbcc" and we go back to step 1
23-
* After steps 1, 2 and 3 of the second iteration, result = "abccbaabc"
24-
* After steps 4, 5 and 6 of the second iteration, result = "abccbaabccba"
25-
*
26-
* Example 2:
27-
* Input: s = "rat"
28-
* Output: "art"
29-
* Explanation: The word "rat" becomes "art" after re-ordering it with the mentioned algorithm.
30-
*
31-
* Example 3:
32-
* Input: s = "leetcode"
33-
* Output: "cdelotee"
34-
*
35-
* Example 4:
36-
* Input: s = "ggggggg"
37-
* Output: "ggggggg"
38-
*
39-
* Example 5:
40-
* Input: s = "spo"
41-
* Output: "ops"
42-
*
43-
* Constraints:
44-
* 1 <= s.length <= 500
45-
* s contains only lower-case English letters.
46-
* */
473
public class _1370 {
484
public static class Solution1 {
495
public String sortString(String s) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy