Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4d4a649

Browse files
add
1 parent 14e0dbc commit 4d4a649

File tree

7 files changed

+315
-0
lines changed

7 files changed

+315
-0
lines changed

‎src/LeetcodeQuestions/SubsetSum.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package LeetcodeQuestions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class SubsetSum {
7+
8+
9+
10+
public static void helper(int arr[], int tar, int sum, int i, List<Integer> out,
11+
List<List<Integer>> res) {
12+
13+
14+
if (sum > tar) {
15+
return;
16+
}
17+
if (tar == sum) {
18+
19+
res.add(new ArrayList<>(out));
20+
return;
21+
}
22+
23+
24+
for (int k = i; k < arr.length; k++) {
25+
26+
out.add(arr[k]);
27+
helper(arr, tar, sum + arr[k], k, out, res);
28+
out.remove(out.size() - 1);
29+
}
30+
31+
32+
33+
}
34+
35+
36+
public static List<List<Integer>> combSum(int arr[], int tar) {
37+
38+
List<Integer> out = new ArrayList<>();
39+
List<List<Integer>> res = new ArrayList<>();
40+
helper(arr, tar, 0, 0, out, res);
41+
42+
return res;
43+
44+
45+
}
46+
47+
48+
49+
public static void main(String[] args) {
50+
51+
int arr[] = {2, 3, 6, 7};
52+
int tar = 7;
53+
for (List<Integer> li : combSum(arr, tar)) {
54+
55+
System.out.println(li);
56+
57+
}
58+
59+
60+
61+
}
62+
63+
64+
65+
}

‎src/LeetcodeQuestions/uniquePath.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package LeetcodeQuestions;
2+
3+
import recursion.quicksort;
4+
5+
// https://leetcode.com/problems/unique-paths/
6+
// https://leetcode.com/problems/unique-paths-ii/
7+
public class uniquePath {
8+
9+
10+
11+
public static boolean uniquePathone() {
12+
13+
14+
15+
16+
17+
}
18+
19+
20+
21+
public static void main(String[] args) {
22+
23+
int arr[][]={{0,0,0},{0,1,0},{0,0,0}};
24+
25+
26+
27+
System.out.println();
28+
29+
}
30+
31+
}

‎src/arrays/AlternateArrayarrange.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package arrays;
2+
3+
public class AlternateArrayarrange {
4+
5+
6+
public static int[] helper(int n) {
7+
8+
9+
10+
int arr[] = new int[n];
11+
int val = 1, s = 0, e = n - 1;
12+
while (s < e) {
13+
14+
15+
arr[s] = val;
16+
val++;
17+
arr[e] = val;
18+
19+
val++;
20+
21+
s++;
22+
e--;
23+
24+
}
25+
26+
if (n % 2 != 0) {
27+
28+
arr[s] = val;
29+
}
30+
31+
32+
return arr;
33+
34+
}
35+
36+
37+
public static void main(String[] args) {
38+
39+
}
40+
}

‎src/arrays/IntersectionArrays.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package arrays;
2+
3+
public class IntersectionArrays {
4+
5+
6+
public static void helper(int[] input1, int[] input2) {
7+
8+
int n = input1.length;
9+
int m = input2.length;
10+
11+
for (int i = 0; i < n; i++) {
12+
13+
for (int j = 0; j < m; j++) {
14+
15+
16+
if (input1[i] == input2[j]) {
17+
18+
System.out.println(input1[i]);
19+
input2[j] = Integer.MIN_VALUE;
20+
break;
21+
22+
}
23+
}
24+
}
25+
26+
}
27+
28+
public static void main(String[] args) {
29+
30+
}
31+
32+
}

‎src/arrays/arraySum.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package arrays;
2+
3+
public class arraySum {
4+
5+
6+
public static int sum(int[] input) {
7+
8+
int sum = 0;
9+
for (int i = 0; i < input.length; i++) {
10+
11+
sum += input[i];
12+
13+
14+
}
15+
16+
17+
return sum;
18+
19+
}
20+
21+
public static int linearSearch(int[] arr, int num) {
22+
23+
24+
for (int i = 0; i < arr.length; i++) {
25+
26+
27+
if (arr[i] == num) {
28+
29+
return i;
30+
}
31+
32+
33+
}
34+
35+
return -1;
36+
37+
38+
}
39+
40+
public static void main(String[] args) {
41+
42+
}
43+
44+
45+
}

‎src/arrays/swapAlternate.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package arrays;
2+
3+
public class swapAlternate {
4+
5+
6+
public static void helper(int[] input) {
7+
8+
int n = input.length;
9+
for (int i = 0; i < n - 1; i += 2) {
10+
11+
12+
13+
int temp = input[i];
14+
input[i] = input[i + 1];
15+
input[i + 1] = temp;
16+
17+
18+
19+
}
20+
21+
}
22+
23+
public static void main(String[] args) {
24+
25+
}
26+
27+
}

‎src/arrays/uniqueElement.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package arrays;
2+
3+
public class uniqueElement {
4+
5+
6+
public static int uniquehelper(int[] arr) {
7+
8+
int pos = -1;
9+
boolean unique = true;
10+
int i, j;
11+
for (i = 0; i < arr.length; i++) {
12+
13+
unique = true;
14+
for (j = 0; j < arr.length; j++) {
15+
16+
17+
if (i != j && arr[i] == arr[j]) {
18+
unique = false;
19+
}
20+
21+
22+
}
23+
if (unique) {
24+
25+
26+
pos = i;
27+
break;
28+
29+
}
30+
31+
}
32+
33+
34+
35+
return arr[pos];
36+
37+
38+
39+
}
40+
41+
42+
public static int duplicatehelper(int[] arr) {
43+
44+
int pos = -1;
45+
46+
int i, j;
47+
for (i = 0; i < arr.length; i++) {
48+
49+
50+
for (j = 0; j < arr.length; j++) {
51+
52+
53+
if (i != j && arr[i] == arr[j]) {
54+
55+
pos = i;
56+
57+
break;
58+
59+
}
60+
61+
}
62+
}
63+
64+
65+
66+
return arr[pos];
67+
68+
}
69+
70+
71+
72+
public static void main(String[] args) {
73+
74+
}
75+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /