|
1 |
| -# Pairs of Songs With Total Durations Divisible by 60 |
2 |
| -You are given a list of songs where the ith song has a duration of time[i] seconds. |
| 1 | +# Check If Two String Arrays are Equivalent |
3 | 2 |
|
4 |
| -Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0. |
| 3 | +Solution |
| 4 | +Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. |
| 5 | + |
| 6 | +A string is represented by an array if the array elements concatenated in order forms the string. |
5 | 7 |
|
6 | 8 |
|
7 | 9 |
|
8 | 10 | Example 1:
|
9 | 11 |
|
10 |
| -Input: time = [30,20,150,100,40] |
11 |
| -Output: 3 |
12 |
| -Explanation: Three pairs have a total duration divisible by 60: |
13 |
| -(time[0] = 30, time[2] = 150): total duration 180 |
14 |
| -(time[1] = 20, time[3] = 100): total duration 120 |
15 |
| -(time[1] = 20, time[4] = 40): total duration 60 |
| 12 | +Input: word1 = ["ab", "c"], word2 = ["a", "bc"] |
| 13 | +Output: true |
| 14 | +Explanation: |
| 15 | +word1 represents string "ab" + "c" -> "abc" |
| 16 | +word2 represents string "a" + "bc" -> "abc" |
| 17 | +The strings are the same, so return true. |
16 | 18 | Example 2:
|
17 | 19 |
|
18 |
| -Input: time = [60,60,60] |
19 |
| -Output: 3 |
20 |
| -Explanation: All three pairs have a total duration of 120, which is divisible by 60. |
| 20 | +Input: word1 = ["a", "cb"], word2 = ["ab", "c"] |
| 21 | +Output: false |
| 22 | +Example 3: |
| 23 | + |
| 24 | +Input: word1 = ["abc", "d", "defg"], word2 = ["abcddefg"] |
| 25 | +Output: true |
21 | 26 |
|
22 | 27 |
|
23 | 28 | Constraints:
|
24 | 29 |
|
25 |
| -1 <= time.length <= 6 * 104 |
26 |
| -1 <= time[i] <= 500 <br> |
| 30 | +1 <= word1.length, word2.length <= 103 |
| 31 | +1 <= word1[i].length, word2[i].length <= 103 |
| 32 | +1 <= sum(word1[i].length), sum(word2[i].length) <= 103 |
| 33 | +word1[i] and word2[i] consist of lowercase letters.<br> |
27 | 34 |
|
28 | 35 | ## Idea
|
29 | 36 |
|
30 | 37 | ## Code
|
31 | 38 | ```python
|
32 | 39 | class Solution:
|
33 |
| - def numPairsDivisibleBy60(self, time: List[int]) -> int: |
34 |
| - |
35 |
| - count = 0 |
36 |
| - d = collections.defaultdict(int) |
37 |
| - |
| 40 | + def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: |
| 41 | + t1 = "" |
| 42 | + t2 = "" |
| 43 | + for i in word1: |
| 44 | + t1 += i |
| 45 | + |
| 46 | + for j in word2: |
| 47 | + t2 += j |
38 | 48 |
|
39 |
| - for item in time: |
40 |
| - if item % 60 == 0: |
41 |
| - count += d[0] |
42 |
| - else: |
43 |
| - count += d[60-item%60] |
44 |
| - d[item%60] += 1 |
45 |
| - |
46 |
| - return count |
| 49 | + return t1 == t2 |
47 | 50 | ```
|
0 commit comments