코딩테스트 풀이/JAVA
[LeetCode/Easy] 389. Find the Difference
무지맘
2023. 5. 18. 11:43
1. Input
1) String s
2) String t
2. Output
1) s가 t가 되기 위해서 추가해야 하는 문자를 반환
3. Constraint
1) 0 <= s.length <= 1000
2) t.length == s.length + 1
3) s와 t는 영어 소문자로만 이루어져 있다.
4. Example
Input: s = "abcd", t = "abcde" -> Output: "e"
5. Code
1) 첫 코드(2023/05/18)
class Solution {
public char findTheDifference(String s, String t) {
ArrayList<Character> list = new ArrayList<Character>();
for(int i=0 ; i<t.length() ; i++)
list.add(t.charAt(i));
for(int i=0 ; i<s.length() ; i++)
list.remove(Character.valueOf(s.charAt(i)));
return list.get(0);
}
}