Skip to content

Commit 17db9b2

Browse files
find the difference
1 parent d5017db commit 17db9b2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package _20160827_2nd_contest;
2+
3+
public class FindTheDifference {
4+
public char findTheDifference(String s, String t) {
5+
int[] counts = new int[128];
6+
char[] schars = s.toCharArray();
7+
char[] tchars = t.toCharArray();
8+
for(int i = 0; i < schars.length; i++){
9+
counts[schars[i]]++;
10+
}
11+
for(int i = 0; i < tchars.length; i++){
12+
counts[tchars[i]]--;
13+
}
14+
char result = 'a';
15+
for(int i = 0; i < 128; i++){
16+
if(counts[i] != 0) result = (char) i;
17+
}
18+
return result;
19+
}
20+
}

0 commit comments

Comments
 (0)