Skip to content

Commit 6a312bb

Browse files
authored
Create Avalon.md
443 我的例程在官网的测试中显示失败,但是我用失败的例子试了应该是对了
1 parent 3261b01 commit 6a312bb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

2018.11.29-leetcode443/Avalon.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public static int compress(char[] chars) {
2+
Map<Character, String> map = new LinkedHashMap();
3+
int len = chars.length;
4+
for (int i = 0; i<len;i++){
5+
if (map.containsKey(chars[i])){
6+
map.put(chars[i],String.valueOf(Integer.parseInt(map.get(chars[i])) + 1));
7+
}else map.put(chars[i],"1");
8+
}
9+
int num = 0;
10+
for (Map.Entry<Character, String> entry : map.entrySet()) {
11+
num++;
12+
if (!entry.getValue().equals("1")){
13+
num += entry.getValue().toCharArray().length ;
14+
}
15+
}
16+
return num;
17+
}

0 commit comments

Comments
 (0)