Java Solution using List


  • 0
    G
    public class Solution {
        public char findTheDifference(String s, String t) {
            List<Character> ls = new ArrayList<>();
            for(int i=0;i<t.length();i++){
                ls.add(t.charAt(i));
            }
            //System.out.println(ls);
            Character c;
            for(int i=0;i<s.length();i++){
                c = s.charAt(i);
                //System.out.println("Removing " + c);
                ls.remove(c);
            }
            return ls.get(0);
        }
    }
    

Log in to reply
 

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