출처 : https://leetcode.com/problems/find-the-difference/?envType=study-plan-v2&envId=programming-skills
You are given two strings s
and t
.
String t
is generated by random shuffling string s
and then add one more letter at a random position.
Return the letter that was added to t
.
class Solution {
public char findTheDifference(String s, String t) {
ArrayList<Character> ss = new ArrayList<>();
ArrayList<Character> tt = new ArrayList<>();
if (s.length() == 0) {
return t.charAt(0);
} else {
for (int a = 0; a < s.length(); a++) {
ss.add(s.charAt(a));
}
for (int b = 0; b < t.length(); b++) {
tt.add(t.charAt(b));
}
}
for (Character c : ss) {
tt.remove(c);
}
return tt.iterator().next();
}
}```