반응형
Notice
Recent Posts
Recent Comments
- Today
- Total
작심삼일
[LeetCode] 1662 | Check If Two String Arrays are Equi 본문
728x90
반응형
문제 링크: https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/
문제
Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.
A string is represented by an array if the array elements concatenated in order forms the string.
조건
- 1 <= word1.length, word2.length <= $10^3$
- 1 <= word1[i].length, word2[i].length <= $10^3$
- 1 <= sum(word1[i].length), sum(word2[i].length) <= $10^3$
- word1[i] and word2[i] consist of lowercase letters.
내 풀이
''.join(word1)을 사용하면 word1 안의 모든 글자들이 하나로 이어지게 된다. (ex. word1 = ['ab', 'cd'], ''.join(word1) $\rightarrow$ 'abcd')
따라서 삼항 연산자를 이용해 word1을 모두 붙인 글과 word2를 모두 붙인 글이 같다면 True를 리턴하고, 그렇지 않다면 False를 리턴한다.
코드
class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return True if ''.join(word1) == ''.join(word2) else False
728x90
반응형
'스터디 > 코테' 카테고리의 다른 글
[LeetCode] 766 | Toeplitz Matrix | Python (0) | 2022.10.31 |
---|---|
[LeetCode] 523 | Continuous Subarray Sum | Python (0) | 2022.10.26 |
[LeetCode] 1239 | Maximum Length of a Concatenated String with Unique Characters | Python (0) | 2022.10.24 |
[LeetCode] 219 | Contains Duplicate II | Python (0) | 2022.10.21 |
[LeetCode] 12 | Integer to Roman | Python (0) | 2022.10.20 |
Comments