Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 1.02 KB

풀이_LC389.md

File metadata and controls

36 lines (27 loc) · 1.02 KB

😼 LeetCode 389. Find the Difference

  • Date : 2021.06.20(일)
  • Time : 10분

Problem

  • You are given two strings s and t. String t is generated by random shuffling string s and then add one more letter at a random position. Return the letter that was added to t.

Constraints

  • 0 <= s.length <= 1000
  • t.length == s.length + 1
  • s and t consist of lower-case English letters.

Example

  • Input: s = "abcd", t = "abcde"
  • Output: "e"
  • Explanation: 'e' is the letter that was added.



풀이

    def findTheDifference(self, s: str, t: str) -> str:
        s = sorted(list(s))
        t = sorted(list(t))
        lengthString = len(t)
        i = 0
        
        while (i < lengthString - 1) and (s[i] == t[i]):
            i += 1
        return t[i]

: 먼저 문자열 두개 모두 정렬을 해준다. 그 다음 앞에서부터 같은지 안같은지 비교해나가면 된다! 아주 .. 쉬운.. 문제.. while문을 이용해도 되지만 단순히 for문을 이용해도 될 것 같다.