Skip to content

Commit 54f3bdc

Browse files
committed
2 parents 1a8ad2e + 2b0a378 commit 54f3bdc

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
fun minCostClimbingStairs(cost: IntArray): Int {
3+
var c1 = cost[0]
4+
var c2 = cost[1]
5+
for (i in 2 until cost.size) {
6+
val cost = cost[i]
7+
c1 = min(c1, c2) + cost
8+
val tmp = c1
9+
c1 = c2
10+
c2 = tmp
11+
}
12+
return min(c1, c2)
13+
}
14+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
class Solution {
5+
6+
static int[][] findPairsWithGivenDifference(int[] arr, int k) {
7+
HashSet<Integer> set = new HashSet<>();
8+
ArrayList<int[]> res = new ArrayList<>();
9+
10+
for (int i = 0; i < arr.length; i++) {
11+
set.add(arr[i]);
12+
}
13+
for (int i = 0; i < arr.length; i++) {
14+
int y = arr[i];
15+
int x = k + y;
16+
if (set.contains(x)) {
17+
res.add(new int[] {x, y});
18+
}
19+
//x - y = k
20+
//x = k + y
21+
}
22+
return res.toArray(new int[0][0]);
23+
}
24+
25+
public static void main(String[] args) {}
26+
27+
}

0 commit comments

Comments
 (0)