Skip to content

Commit 9ecdb43

Browse files
committed
18/12/2020
1 parent e8f18ad commit 9ecdb43

File tree

3 files changed

+52
-18
lines changed

3 files changed

+52
-18
lines changed

Daily-challenge/Dec/17/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,22 @@ The two tuples are:
2525
## Code
2626
```python
2727
class Solution:
28-
def mirrorReflection(self, p: int, q: int) -> int:
29-
while p % 2 == 0 and q % 2 == 0: p, q = p / 2, q / 2
30-
return int(1 - p % 2 + q % 2)
31-
28+
def fourSumCount(self, A: List[int], B: List[int], C: List[int], D: List[int]) -> int:
29+
count = 0
30+
num_dict = {}
31+
for i in C:
32+
for j in D:
33+
s = i + j
34+
if s in num_dict:
35+
num_dict[s] += 1
36+
else:
37+
num_dict[s] = 1
38+
39+
for i in range(len(A)):
40+
for j in range(len(B)):
41+
target = 0 - (A[i]+B[j])
42+
if target in num_dict:
43+
count += num_dict[target]
44+
return count
3245
```
3346

Daily-challenge/Dec/17/sol.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
class Solution:
2-
def mirrorReflection(self, p: int, q: int) -> int:
3-
while p % 2 == 0 and q % 2 == 0: p, q = p / 2, q / 2
4-
return int(1 - p % 2 + q % 2)
2+
def fourSumCount(self, A: List[int], B: List[int], C: List[int], D: List[int]) -> int:
3+
count = 0
4+
num_dict = {}
5+
for i in C:
6+
for j in D:
7+
s = i + j
8+
if s in num_dict:
9+
num_dict[s] += 1
10+
else:
11+
num_dict[s] = 1
12+
13+
for i in range(len(A)):
14+
for j in range(len(B)):
15+
target = 0 - (A[i]+B[j])
16+
if target in num_dict:
17+
count += num_dict[target]
18+
return count

Daily-challenge/Dec/18/README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
# Merge Intervals
2-
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
1+
# Increasing Triplet Subsequence
2+
Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false.
33

44

55

66
Example 1:
77

8-
Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
9-
Output: [[1,6],[8,10],[15,18]]
10-
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
8+
Input: nums = [1,2,3,4,5]
9+
Output: true
10+
Explanation: Any triplet where i < j < k is valid.
1111
Example 2:
1212

13-
Input: intervals = [[1,4],[4,5]]
14-
Output: [[1,5]]
15-
Explanation: Intervals [1,4] and [4,5] are considered overlapping.
13+
Input: nums = [5,4,3,2,1]
14+
Output: false
15+
Explanation: No triplet exists.
16+
Example 3:
17+
18+
Input: nums = [2,1,5,0,4,6]
19+
Output: true
20+
Explanation: The triplet (3, 4, 5) is valid because nums[3] == 0 < nums[4] == 4 < nums[5] == 6.
1621

1722

1823
Constraints:
1924

20-
1 <= intervals.length <= 104
21-
intervals[i].length == 2
22-
0 <= starti <= endi <= 104<br>
25+
1 <= nums.length <= 105
26+
-231 <= nums[i] <= 231 - 1
27+
28+
29+
Follow up: Could you implement a solution that runs in O(n) time complexity and O(1) space complexity?<br>
2330

2431
## Idea
2532
Just do while loop and convert to decimal

0 commit comments

Comments
 (0)