Java Array 89.73% 6ms


  • 0
    H

    Welcome your advice. Thanks.

    public class Solution {
        public char findTheDifference(String s, String t) {
            int[] hash = new int[256];
            
            for (char ch : s.toCharArray()) {
                hash[ch]++;
            }
            
            for (char ch : t.toCharArray()) {
                if (hash[ch] >= 1) {
                    hash[ch]--;
                }
                else 
                    return ch;
            }
            return 0;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.