[LeetCode] 389. Find the Difference

2020. 3. 25. 01:49ยท ๐Ÿ–ฅ๏ธ Computer/Algorithm Solution

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  (4) 2020.03.24
[LeetCode] 7. Reverse Integer  (1) 2020.03.23
'๐Ÿ–ฅ๏ธ Computer/Algorithm Solution' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • [BAEKJOON] 10814๋ฒˆ : ๋‚˜์ด์ˆœ ์ •๋ ฌ
  • [BAEKJOON] 2960๋ฒˆ : ์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด
  • [LeetCode] 397. Integer Replacement
  • [LeetCode] 278. First Bad Version
_์ฃผ๋…ธ
_์ฃผ๋…ธ
_์ฃผ๋…ธ
juno.log
_์ฃผ๋…ธ
์ „์ฒด
์˜ค๋Š˜
์–ด์ œ
  • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (88)
    • ๐Ÿ’ฌ Language (15)
      • C (1)
      • C++ (1)
      • Java (12)
    • ๐Ÿ–ฅ๏ธ Computer (46)
      • Data Structure (2)
      • Computer Science (3)
      • Algorithm Solution (41)
    • ๐ŸŒฑ Spring (14)
    • ๐Ÿ“ฆ Database (1)
    • ๐Ÿฅณ Project (6)
      • kakao chatbot (6)
    • ๐Ÿ˜† Daily (5)
      • ์žก๋‹ด (5)
      • TIL (0)

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • ํ™ˆ
  • ๋ธ”๋กœ๊ทธ ๊ด€๋ฆฌ
  • GitHub
  • Velog

์ธ๊ธฐ ๊ธ€

hELLO ยท Designed By ์ •์ƒ์šฐ.v4.2.0
_์ฃผ๋…ธ
[LeetCode] 389. Find the Difference
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”

๊ฐœ์ธ์ •๋ณด

  • ํ‹ฐ์Šคํ† ๋ฆฌ ํ™ˆ
  • ํฌ๋Ÿผ
  • ๋กœ๊ทธ์ธ

๋‹จ์ถ•ํ‚ค

๋‚ด ๋ธ”๋กœ๊ทธ

๋‚ด ๋ธ”๋กœ๊ทธ - ๊ด€๋ฆฌ์ž ํ™ˆ ์ „ํ™˜
Q
Q
์ƒˆ ๊ธ€ ์“ฐ๊ธฐ
W
W

๋ธ”๋กœ๊ทธ ๊ฒŒ์‹œ๊ธ€

๊ธ€ ์ˆ˜์ • (๊ถŒํ•œ ์žˆ๋Š” ๊ฒฝ์šฐ)
E
E
๋Œ“๊ธ€ ์˜์—ญ์œผ๋กœ ์ด๋™
C
C

๋ชจ๋“  ์˜์—ญ

์ด ํŽ˜์ด์ง€์˜ URL ๋ณต์‚ฌ
S
S
๋งจ ์œ„๋กœ ์ด๋™
T
T
ํ‹ฐ์Šคํ† ๋ฆฌ ํ™ˆ ์ด๋™
H
H
๋‹จ์ถ•ํ‚ค ์•ˆ๋‚ด
Shift + /
โ‡ง + /

* ๋‹จ์ถ•ํ‚ค๋Š” ํ•œ๊ธ€/์˜๋ฌธ ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ํ‹ฐ์Šคํ† ๋ฆฌ ๊ธฐ๋ณธ ๋„๋ฉ”์ธ์—์„œ๋งŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.