MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Sanghoo

Class Sanghoo

LeetCode/String/389. Find the Difference/Sanghoo.java:6–30  ·  view source on GitHub ↗

https://leetcode.com/problems/find-the-difference/

Source from the content-addressed store, hash-verified

4 * https://leetcode.com/problems/find-the-difference/
5 */
6public class Sanghoo {
7
8 // 기존 많이 사용했던 알파벳별 개수를 이용하였습니다.
9 public char findTheDifference(String s, String t) {
10 char res = '0';
11 int[] arr = new int[26];
12
13 for(int i=0; i<t.length(); i++) {
14 if(i < s.length()) {
15 arr[s.charAt(i)-'a']++;
16 }
17 arr[t.charAt(i)-'a']--;
18 }
19
20 for(int i=0; i<arr.length; i++) {
21 if(arr[i] < 0) {
22 res = (char)(i+'a');
23 break;
24 }
25 }
26
27 return res;
28 }
29
30}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected