Skip to content

Commit d387c30

Browse files
committed
dayN
1 parent 7acec8e commit d387c30

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

Daily-challenge/2021/Jan/08/README.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
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
32

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.
57

68

79

810
Example 1:
911

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.
1618
Example 2:
1719

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
2126

2227

2328
Constraints:
2429

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>
2734

2835
## Idea
2936

3037
## Code
3138
```python
3239
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
3848

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
4750
```

Daily-challenge/2021/Jan/08/sol.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
class Solution:
2-
def numPairsDivisibleBy60(self, time: List[int]) -> int:
3-
4-
count = 0
5-
d = collections.defaultdict(int)
6-
2+
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
3+
t1 = ""
4+
t2 = ""
5+
for i in word1:
6+
t1 += i
77

8-
for item in time:
9-
if item % 60 == 0:
10-
count += d[0]
11-
else:
12-
count += d[60-item%60]
13-
d[item%60] += 1
14-
15-
return count
8+
for j in word2:
9+
t2 += j
10+
11+
return t1 == t2

0 commit comments

Comments
 (0)