Skip to content

Commit a2a8ce5

Browse files
main
1 parent e0ce817 commit a2a8ce5

File tree

5 files changed

+160
-1
lines changed

5 files changed

+160
-1
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"5.ControlStatement\\ifElse\\Assignments",
1010
"5.ControlStatement\\ifElse\\ClassCodes",
1111
"6.String",
12-
"7.InputOutput"
12+
"7.InputOutput",
13+
"8,Method"
1314
]
1415
}

3.Array/LeetCode/program65.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
3+
/*
4+
5+
35. Search Insert Position
6+
Easy
7+
13.3K
8+
580
9+
Companies
10+
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
11+
12+
You must write an algorithm with O(log n) runtime complexity.
13+
14+
Example 1:
15+
Input: nums = [1,3,5,6], target = 5
16+
Output: 2
17+
18+
Example 2:
19+
Input: nums = [1,3,5,6], target = 2
20+
Output: 1
21+
22+
Example 3:
23+
Input: nums = [1,3,5,6], target = 7
24+
Output: 4
25+
26+
*/
27+
28+
29+
30+
package LeetCode;
31+
public class program65 {
32+
33+
static int searchInsert(int[] nums, int target) {
34+
35+
for(int i=0;i<nums.length;i++){
36+
37+
if(nums[i]==target){
38+
return i;
39+
}
40+
41+
if(nums[i]>target){
42+
return i;
43+
}
44+
45+
if(i==nums.length-1){
46+
return i+1;
47+
}
48+
}
49+
50+
return -1;
51+
}
52+
53+
public static void main(String[] args) {
54+
55+
int nums[] = {1,3,5,6};
56+
int target = 5;
57+
58+
System.out.println(searchInsert(nums, target));
59+
60+
}
61+
}

3.Array/LeetCode/program66.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
/*
3+
51. N-Queens
4+
Hard
5+
10.1K
6+
223
7+
Companies
8+
The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.
9+
10+
Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.
11+
12+
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space, respectively.
13+
14+
Example 1:
15+
Input: n = 4
16+
Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
17+
Explanation: There exist two distinct solutions to the 4-queens puzzle as shown above
18+
19+
20+
Example 2:
21+
Input: n = 1
22+
Output: [["Q"]]
23+
24+
*/
25+
26+
27+
28+
29+
package LeetCode;
30+
31+
32+
public class program66 {
33+
public List<List<String>> solveNQueens(int n) {
34+
35+
List<List<String>>ls = new List<>();
36+
37+
List<String>obj = new List<>();
38+
39+
40+
return ls;
41+
}
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ClassCodes;
2+
3+
import java.util.Scanner;
4+
import java.util.StringTokenizer;
5+
6+
public class program15 {
7+
public static void main(String[] args) {
8+
9+
Scanner sc = new Scanner(System.in);
10+
11+
System.out.println("Enter the player: ");
12+
String str = sc.nextLine();
13+
14+
StringTokenizer st = new StringTokenizer(str, " ");
15+
16+
while(st.hasMoreElements()){
17+
18+
System.out.println(st.nextElement());
19+
}
20+
}
21+
}

8,Method/ClassCodes/program1.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
package ClassCodes;
3+
4+
public class program1 {
5+
6+
int x =10;
7+
static void fun(){
8+
System.out.println("Inside Fun method...!");
9+
}
10+
11+
void gun(){
12+
System.out.println("Inside gun method..!");
13+
fun();
14+
}
15+
16+
public static void main(String[] args) {
17+
18+
program1 obj = new program1();
19+
20+
gun();
21+
}
22+
}
23+
24+
25+
26+
/*
27+
28+
program1.java:20: error: non-static method gun() cannot be referenced from a static context
29+
gun();
30+
^
31+
1 error
32+
error: compilation failed
33+
34+
*/

0 commit comments

Comments
 (0)