LeetCode_Study_Plan/Programming Skills
389. Find the Difference java
개발하는루루
2022. 9. 21. 15:28
https://leetcode.com/problems/find-the-difference/
Find the Difference - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution {
public char findTheDifference(String s, String t) {
char[] s_arr = s.toCharArray();
char[] t_arr = t.toCharArray();
Arrays.sort(s_arr);
Arrays.sort(t_arr);
for (int i = 0; i < s_arr.length; i++) {
if(s_arr[i] != t_arr[i]){
return t_arr[i];
}
}
return t_arr[t_arr.length-1];
}
}