Skip to content

Commit 3d62494

Browse files
main
1 parent d59fb4c commit 3d62494

File tree

11 files changed

+239
-27
lines changed

11 files changed

+239
-27
lines changed

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"java.project.sourcePaths": [
3+
"3.Array/ClassCodes",
4+
"3.Array",
5+
"2.Loop",
6+
"1.DataType",
7+
"4.Operators/ClassCodes"
8+
]
9+
}

1.DataType/Program1.java renamed to 1.DataType/PractiseCodes/Program1.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package PractiseCodes;
12
class Datatype{
23

34
public static void main(String[] args){

1.DataType/Program3.java renamed to 1.DataType/PractiseCodes/Program3.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package PractiseCodes;
12
class Demo{
23

34
public void main(String[] args){

3.Array/LeetCode/program1.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
34. Find First and Last Position of Element in Sorted Array
3+
Medium
4+
5+
Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.
6+
7+
If target is not found in the array, return [-1, -1].
8+
9+
You must write an algorithm with O(log n) runtime complexity.
10+
11+
*/
12+
13+
package LeetCode;
14+
15+
16+
public class program1 {
17+
18+
public static void main(String[] args) {
19+
20+
int nums[]={5,7,7,8,8,10};
21+
22+
int target =8;
23+
24+
int left =0;
25+
int right = nums.length-1;
26+
27+
int output[] = new int[2];
28+
29+
while(left<=right){
30+
31+
if(nums[left]==target){
32+
33+
output[0] = left;
34+
35+
while(left<right){
36+
37+
if(nums[right]==target){
38+
39+
output[1] = right;
40+
System.out.println(output[0]+" "+output[1]);
41+
break;
42+
}
43+
44+
else{
45+
46+
right -=1;
47+
}
48+
}
49+
50+
output[1] = left;
51+
System.out.println(output[0]+" "+output[1]);
52+
break;
53+
54+
}
55+
else if(nums[left]<target){
56+
57+
left +=1;
58+
}
59+
else if(nums[right]>target){
60+
right -=1;
61+
}
62+
}
63+
64+
65+
}
66+
67+
}

3.Array/PracticeCodes/Program18.java

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
Program 33 : #LeetCode - Easy
4-
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
4+
Given a non-empty aay of integers nums, every element appears twice except for one. Find that single one.
55
66
You must implement a solution with a linear runtime complexity and use only constant extra space.
77
@@ -20,42 +20,69 @@
2020
Constraints:
2121
1 <= nums.length <= 3 * 104
2222
-3 * 104 <= nums[i] <= 3 * 104
23-
Each element in the array appears twice except for one element which appears only once.
23+
Each element in the aay appears twice except for one element which appears only once.
2424
*/
2525

2626

2727
package PracticeCodes;
28+
import java.io.*;
2829

2930

3031
public class Program18 {
32+
static int singleNumber(int a[]){
33+
34+
for(int i = 0 ; i < a.length; i++){
3135

32-
public static void main(String[] args) {
33-
34-
int a[] = {4,1,2,1,2};
35-
int j=0;
36-
37-
boolean flag = false;
38-
for(int i=0;i<a.length-1;i++){
39-
40-
for(j=i+1;j<a.length;j++){
41-
42-
if(a[i]!=a[j] && i!=j){
36+
for(int j=i+1;j<a.length;j++){
4337

44-
flag = true;
45-
System.out.println(a[i]);
46-
break;
47-
}
38+
if(a[i]>a[j]){
4839

49-
else{
50-
continue;
40+
int temp = a[i];
41+
a[i] = a[j];
42+
a[j] = temp;
5143
}
52-
53-
}
54-
if(flag){
55-
break;
5644
}
57-
45+
46+
}
47+
48+
for(int i=0;i<a.length;i++){
49+
50+
System.out.print(a[i]+" ");
5851
}
59-
}
60-
61-
}
52+
53+
54+
if(a[0] != a[1]){
55+
return a[0];
56+
}
57+
for(int i = 1; i < a.length - 1 ; i++){
58+
59+
if(a[i] != a[i + 1] && a[i] != a[ i - 1]){
60+
61+
return a[i];
62+
}
63+
}
64+
if(a[a.length - 2] != a[a.length - 1]){
65+
return a[a.length - 1];
66+
}
67+
return 0;
68+
}
69+
70+
public static void main(String[] args)throws IOException{
71+
72+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
73+
74+
System.out.println("Enter the size of aay : ");
75+
int size = Integer.parseInt(br.readLine());
76+
77+
int[] a = new int[size];
78+
79+
System.out.println("Enter the aay Elements : ");
80+
for(int i = 0 ; i < size; i++){
81+
82+
a[i] = Integer.parseInt(br.readLine());
83+
}
84+
85+
int single = singleNumber(a);
86+
System.out.println("Single Element : " + single);
87+
}
88+
}

4.Operators/ClassCodes/Program1.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
public class Program1 {
3+
public static void main(String[] args) {
4+
5+
int x = 10;
6+
int y =20;
7+
8+
System.out.println(x+y);
9+
System.out.println(x-y);
10+
System.out.println(x*y);
11+
System.out.println(x/y);
12+
System.out.println(x%y);
13+
14+
15+
16+
}
17+
}

4.Operators/ClassCodes/Program2.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Program2 {
2+
public static void main(String[] args) {
3+
4+
int x = 4;
5+
int y =5;
6+
7+
int z =6;
8+
9+
int ans = x+y*z+(x-y);
10+
11+
System.out.println(ans);
12+
13+
}
14+
}

4.Operators/ClassCodes/Program3.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Program3 {
2+
public static void main(String[] args) {
3+
4+
int x =10;
5+
int y =20;
6+
7+
System.out.println(x<y);
8+
System.out.println(x>y);
9+
System.out.println(x!=y);
10+
System.out.println(x==y);
11+
12+
}
13+
}

4.Operators/ClassCodes/Program4.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Program4 {
2+
public static void main(String[] args) {
3+
4+
int x =10;
5+
int y=20;
6+
7+
if(x<y){
8+
System.out.println("Hello");
9+
}
10+
11+
else{
12+
13+
System.out.println("Hii...!");
14+
}
15+
}
16+
}

4.Operators/ClassCodes/Program5.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public class Program5 {
2+
public static void main(String[] args) {
3+
4+
// int x =10;
5+
// int y=20;
6+
7+
// if(true){
8+
9+
// System.out.println("Hello..!");
10+
// }
11+
12+
// else{
13+
14+
// System.out.println("hi..!");
15+
// }
16+
17+
18+
// if(x){
19+
20+
// System.out.println("Hello..!"); //Error:Incompatible types: Int can't be converted into boolean
21+
// }
22+
23+
// else{
24+
25+
// System.out.println("hi..!");
26+
// }
27+
28+
29+
30+
31+
}
32+
}

4.Operators/ClassCodes/Program6.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class Program6 {
2+
public static void main(String[] args) {
3+
4+
int x =5;
5+
int y =7;
6+
7+
8+
9+
System.out.println(x++);
10+
System.out.println(y++);
11+
System.out.println(x--);
12+
System.out.println(y--);
13+
14+
}
15+
}

0 commit comments

Comments
 (0)