| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- docker
- Clone
- C++
- var
- security
- npm
- scss
- Python
- leetcode
- vue.js
- BOJ
- machine learning
- property
- loop
- vuetify
- 앙상블
- generic
- dotenv
- nginx
- git
- webpack
- VUE
- JavaScript
- bash
- C#
- 보안
- AI
- type
- condition
- TypeScript
Archives
- Today
- Total
ice rabbit programming
[LeetCode] 389. Find the Difference 본문
728x90
leetcode.com/problems/find-the-difference/
Find the Difference - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
문자열이 두 개 주어지는데, 임의의 위치에서 하나의 문자가 다르게 들어오는데, 이 문자를 찾는 문제이다.
두 문자를 모두 정렬한 후에 비교해서 다른 index의 문자를 반환하는 식으로 풀었다.
class Solution:
def findTheDifference(self, s: str, t: str) -> str:
sorted_s = sorted(s)
sorted_t = sorted(t)
for index in range(len(s)):
if sorted_t[index] != sorted_s[index]:
return sorted_t[index]
return sorted_t[-1]728x90
'PS > LeetCode' 카테고리의 다른 글
| [LeetCode] 191. Numbers of 1 Bits (0) | 2020.12.08 |
|---|---|
| [LeetCode] 190. Reverse Bits (0) | 2020.12.08 |
| [LeetCode] 448. Find All Numbers Disappeared in an Array (0) | 2020.09.26 |
| [LeetCode] Move Zeroes (0) | 2020.09.06 |
| [LeetCode] May Challenge 9 - Single Element in a Sorted Array (0) | 2020.05.16 |