Skip to content

Commit 9fe07fc

Browse files
add 1663
1 parent 7221c4a commit 9fe07fc

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1663|[Smallest String With A Given Numeric Value](https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1663.java) ||Medium|Greedy|
1112
|1662|[Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1662.java) ||Easy|String|
1213
|1657|[Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1657.java) ||Medium|Greedy|
1314
|1656|[Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1656.java) ||Easy|Array, Design|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1663 {
4+
public static class Solution1 {
5+
public String getSmallestString(int n, int k) {
6+
StringBuilder sb = new StringBuilder();
7+
int balance = k - n;
8+
while (balance > 0) {
9+
if (balance > 25) {
10+
balance -= 25;
11+
sb.append("z");
12+
n--;
13+
} else {
14+
char str = (char) ('a' + balance);
15+
sb.append(str);
16+
n--;
17+
while (n > 0) {
18+
sb.append("a");
19+
n--;
20+
}
21+
break;
22+
}
23+
}
24+
return sb.reverse().toString();
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1663;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1663Test {
10+
private static _1663.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1663.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals("aay", solution1.getSmallestString(3, 27));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals("aaszz", solution1.getSmallestString(5, 73));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)