Shawngbk / Leecode

Questions of Leecode
0 stars 0 forks source link

389. Find the Difference #73

Open Shawngbk opened 7 years ago

Shawngbk commented 7 years ago

类似387 public class Solution { public char findTheDifference(String s, String t) { int[] flag = new int[26]; for(int i = 0; i < s.length(); i++) { flag[s.charAt(i)-'a']++; } for(int i = 0; i < t.length(); i++) { flag[t.charAt(i)-'a']--; if(flag[t.charAt(i)-'a'] < 0) { return t.charAt(i); } } return '-'; } }