Skip to content

Commit 489983d

Browse files
authored
Merge pull request gzc426#170 from a-yin/master
Create 湛江甲鸟.md
2 parents b8bdaf3 + 178b211 commit 489983d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```
2+
public static String reverseWords(String s) {
3+
int len = s.length();
4+
int j = len;
5+
String result = "";
6+
for (int i = len - 1; i >= 0; i--) {
7+
if (s.charAt(i) == ' '){
8+
j = i ;
9+
} else if (i == 0 || s.charAt(i - 1) == ' ') {
10+
if (result.length() != 0) {
11+
result += ' ';
12+
}
13+
result += s.substring(i, j);
14+
}
15+
}
16+
return result;
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```
2+
public int compress(char[] chars) {
3+
int index = 0;
4+
if (chars.length < 2) {
5+
return chars.length;
6+
}
7+
8+
for (int i = 0; i < chars.length; ) {
9+
int times = 1;
10+
chars[index++] = chars[i++];
11+
while (i < chars.length && chars[i] == chars[i - 1]) {
12+
times++;
13+
i++;
14+
}
15+
if (times > 1) {
16+
char[] chs = String.valueOf(times).toCharArray();
17+
for (int j = 0; j < chs.length; j++) {
18+
chars[index++] = chs[j];
19+
}
20+
}
21+
}
22+
return index;
23+
}

0 commit comments

Comments
 (0)