-
leetcode.com/problems/find-the-difference/
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.
처음에는 예제때문에 set으로 푸려고했더니.. "a" "aa" 와 같은 예제가 있었다. 그럼 등장 횟수도 중요한것이니 Counter를 사용하였다.
#1차시도 class Solution: def findTheDifference(self, s: str, t: str) -> str: return list((set(t)-set(s)))[0] #정답 class Solution: def findTheDifference(self, s: str, t: str) -> str: return list((Counter(t)-Counter(s)).keys())[0]
'2020년 > 코테' 카테고리의 다른 글
[leetcode 추석맞이 3문제] minimum-absolute-, differencerepeated-dna-sequences, pseudo-palindromic-paths-in-a-binary-tree (0) 2020.10.01 [codility] 몸풀이용 문제 3개(BinaryGap, CyclicRotation, OddOccurrencesInArray) (0) 2020.09.28 [코테 연습] Product of Array Except Self (0) 2020.09.24 [코테 연습] Fair Candy Swap (0) 2020.09.24 [코테 연습] Valid Parentheses (0) 2020.09.24