Skip to content

Commit 4194813

Browse files
add 1754
1 parent a436c50 commit 4194813

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-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+
|1754|[Largest Merge Of Two Strings](https://leetcode.com/problems/largest-merge-of-two-strings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1753.java) ||Medium|Greedy, Suffix Array|
1112
|1753|[Maximum Score From Removing Stones](https://leetcode.com/problems/maximum-score-from-removing-stones/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1753.java) ||Medium|Math, Heap|
1213
|1752|[Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1752.java) ||Easy|Array|
1314
|1750|[Minimum Length of String After Deleting Similar Ends](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1750.java) ||Medium|Two Pointers|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1754 {
4+
public static class Solution1 {
5+
public String largestMerge(String word1, String word2) {
6+
int i = 0;
7+
int j = 0;
8+
StringBuilder sb = new StringBuilder();
9+
while (i < word1.length() && j < word2.length()) {
10+
if (word1.substring(i).compareTo(word2.substring(j)) > 0) {
11+
sb.append(word1.charAt(i++));
12+
} else {
13+
sb.append(word2.charAt(j++));
14+
}
15+
}
16+
while (i < word1.length()) {
17+
sb.append(word1.charAt(i++));
18+
}
19+
while (j < word2.length()) {
20+
sb.append(word2.charAt(j++));
21+
}
22+
return sb.toString();
23+
}
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1754;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1754Test {
10+
private static _1754.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1754.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals("cbcabaaaaa", solution1.largestMerge("cabaa", "bcaaa"));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)