Given two strings s and t which consist of only lowercase letters.
String t is generated by random shuffling string s and then add one more letter at a random position.
Find the letter that was added in t.
Example:
Input:
s = "abcd"
t = "abcde"
Output:
e Explanation: 'e' is the letter that was added.
์ฝ๋
class Solution {
public:
char findTheDifference(string s, string t) {
long int arr1[27] = {0,};
long int arr2[27] = {0,};
for(int i = 0; i < s.length(); i++){
arr1[s[i]-'a']++;
}
for(int i = 0; i < t.length(); i++){
arr2[t[i]-'a']++;
}
for(int i = 0; i < 26; i++) {
if(arr1[i] < arr2[i])
return (char)(i+'a');
}
return -1;
}
};
์ด๊ฑด ์ซ;; ์๊ฐํ๊ธฐ์ซ์ด์ ๋์ถฉ์งฐ๋๋ ์์ ๋ณ๋ก์ธ์ฝ๋๊ฐ ์ง์!
๋์ค์ ๋ค์์ง๋ด์ผ๊ฒ ๋ค
'๐ฅ๏ธ Computer > Algorithm Solution' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BAEKJOON] 10814๋ฒ : ๋์ด์ ์ ๋ ฌ (0) | 2021.12.11 |
---|---|
[BAEKJOON] 2960๋ฒ : ์๋ผํ ์คํ ๋ค์ค์ ์ฒด (0) | 2020.07.09 |
[LeetCode] 397. Integer Replacement (0) | 2020.03.24 |
[LeetCode] 278. First Bad Version (0) | 2020.03.24 |
[LeetCode] 7. Reverse Integer (0) | 2020.03.23 |