Skip to content

Commit aac5c7b

Browse files
committed
[Aug 01] Added leetcode daily challenge problem
1 parent 0b8baca commit aac5c7b

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

Diff for: leetCode/DailyChallenge/_2022/FEB/_03FEB2022_4SumII.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636
* -2^28 <= nums1[i], nums2[i], nums3[i], nums4[i] <= 2^28
3737
*/
3838
public class _03FEB2022_4SumII {
39-
public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
40-
var pairCountBySum = new HashMap<Integer, Integer>();
41-
for (var num1 : nums1)
42-
for (var num2 : nums2)
43-
pairCountBySum.compute(num1 + num2, (k, sumCount) -> sumCount == null ? 1 : sumCount + 1);
44-
45-
var fourSumCount = 0;
46-
for (var num3 : nums3)
47-
for (var num4 : nums4)
48-
fourSumCount += pairCountBySum.getOrDefault(-(num3 + num4), 0);
49-
50-
return fourSumCount;
51-
}
39+
// public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
40+
// var pairCountBySum = new HashMap<Integer, Integer>();
41+
// for (var num1 : nums1)
42+
// for (var num2 : nums2)
43+
// pairCountBySum.compute(num1 + num2, (k, sumCount) -> sumCount == null ? 1 : sumCount + 1);
44+
//
45+
// var fourSumCount = 0;
46+
// for (var num3 : nums3)
47+
// for (var num4 : nums4)
48+
// fourSumCount += pairCountBySum.getOrDefault(-(num3 + num4), 0);
49+
//
50+
// return fourSumCount;
51+
// }
5252
}

Diff for: leetCode/problems/_62_uniquePaths_1.java

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package leetCode.problems;
2+
3+
public class _62_uniquePaths_1 {
4+
5+
public int solution_recursive(int m, int n) {
6+
return helper_recursive(m, n, 0, 0);
7+
}
8+
9+
public int helper_recursive(int m, int n, int x, int y) {
10+
if (x == m - 1 || y == n - 1) return 1;
11+
if (x >= m || y >= n) return 0;
12+
13+
return helper_recursive(m, n, x + 1, y) + helper_recursive(m, n, x, y + 1);
14+
}
15+
16+
public int solution_dp(int m, int n) {
17+
int[][] dp = new int[m][n];
18+
19+
for (int i = 0; i < m; i++) {
20+
for (int j = 0; j < n; j++) {
21+
if (i == 0 || j == 0) {
22+
dp[i][j] = 1;
23+
} else {
24+
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
25+
}
26+
}
27+
}
28+
29+
return dp[m - 1][n - 1];
30+
}
31+
32+
public int solution_nCr(int m, int n) {
33+
int N = m + n - 2;
34+
int r = Math.min(m, n) - 1;
35+
double ans = 1;
36+
37+
for (int i = 1; i <= r; i++) {
38+
ans = ans * (N - r + i) / i;
39+
}
40+
41+
return (int) ans;
42+
43+
}
44+
45+
public static void main(String[] args) {
46+
47+
_62_uniquePaths_1 obj = new _62_uniquePaths_1();
48+
System.out.println(obj.solution_recursive(3, 2));
49+
}
50+
}

0 commit comments

Comments
 (0)