작심삼일

[LeetCode] 1662 | Check If Two String Arrays are Equi 본문

스터디/코테

[LeetCode] 1662 | Check If Two String Arrays are Equi

yun_s 2022. 10. 25. 09:06
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
반응형
Comments