Skip to content

Commit 975035c

Browse files
add 2000
1 parent 80de360 commit 975035c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

+1
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+
|2000|[Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_2000.java) ||Easy||
1112
|1996|[The Number of Weak Characters in the Game](https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1996.java) ||Medium||
1213
|1995|[Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1995.java) ||Easy||
1314
|1992|[Find All Groups of Farmland](https://leetcode.com/problems/find-all-groups-of-farmland/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1992.java) ||Medium||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2000 {
4+
public static class Solution1 {
5+
public String reversePrefix(String word, char ch) {
6+
int end = word.length();
7+
for (int i = 0; i < word.length(); i++) {
8+
if (word.charAt(i) == ch) {
9+
end = i;
10+
break;
11+
}
12+
}
13+
if (end == word.length()) {
14+
return word;
15+
}
16+
StringBuilder sb = new StringBuilder(word.substring(0, end + 1));
17+
sb.reverse();
18+
sb.append(word.substring(end + 1));
19+
return sb.toString();
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)