Skip to content

Commit e5fcede

Browse files
committed
update
1 parent 5ef02a2 commit e5fcede

File tree

18 files changed

+102
-135
lines changed

18 files changed

+102
-135
lines changed

src/main/java/com/leetcode/Practice10_MergeSortedLists.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/main/java/com/leetcode/Practice11.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/main/java/com/leetcode/Practice5.java renamed to src/main/java/com/leetcode/array/ArrayOne.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package com.leetcode;
1+
package com.leetcode.array;
22

33
import java.util.ArrayList;
44
import java.util.HashMap;
55
import java.util.function.BiConsumer;
66
import java.util.List;
77

8-
public class Practice5 {
8+
public class ArrayOne {
99
/**
1010
*
1111
* find the disappeared numbers in array

src/main/java/com/leetcode/Practice5_s.java renamed to src/main/java/com/leetcode/array/ArrayOneS.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.leetcode;
1+
package com.leetcode.array;
22

3-
public class Practice5_s {
3+
public class ArrayOneS {
44

55

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

src/main/java/com/leetcode/Practice3.java renamed to src/main/java/com/leetcode/doublepointer/DoublePointerOne.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.leetcode;
1+
package com.leetcode.doublepointer;
22

3-
public class Practice3 {
3+
public class DoublePointerOne {
44

55
/**
66
*
@@ -50,4 +50,36 @@ public static void main(String[] args) {
5050
}
5151

5252
}
53+
54+
/**
55+
*
56+
* name: Container With Most Water
57+
*
58+
*/
59+
public static class Practice6 {
60+
public static int maxArea(int[] height) {
61+
int maxarea = 0;
62+
for(int i = 1 ; i < height.length ; i ++){
63+
for( int j = height.length -1 ; j > i ; j --){
64+
int minHeight = Math.min(height[j], height[i]);
65+
int area = (j-i) * minHeight;
66+
if(area > maxarea){
67+
maxarea = area;
68+
}
69+
}
70+
}
71+
72+
return maxarea;
73+
}
74+
75+
76+
public static void main(String[] args) {
77+
// test case 1
78+
int[] height = {1,8,6,2,5,4,8,3,7};
79+
// test case 2
80+
// int[] height = {1,1};
81+
int maxArea = maxArea(height);
82+
System.out.println(maxArea);
83+
}
84+
}
5385
}

src/main/java/com/leetcode/Practice6.java renamed to src/main/java/com/leetcode/doublepointer/DoublePointerThree.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
package com.leetcode;
1+
package com.leetcode.doublepointer;
22

3-
public class Practice6 {
3+
/**
4+
*
5+
* Container With Most Water
6+
*
7+
*/
8+
public class DoublePointerThree {
49
public static int maxArea(int[] height) {
510
int maxarea = 0;
611
for(int i = 1 ; i < height.length ; i ++){
@@ -21,8 +26,8 @@ public static void main(String[] args) {
2126
// test case 1
2227
int[] height = {1,8,6,2,5,4,8,3,7};
2328
// test case 2
24-
// int[] height = {1,1};
29+
// int[] height = {1,1};
2530
int maxArea = maxArea(height);
2631
System.out.println(maxArea);
2732
}
28-
}
33+
}

src/main/java/com/leetcode/Practice4.java renamed to src/main/java/com/leetcode/doublepointer/DoublePointerTwo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package com.leetcode;
1+
package com.leetcode.doublepointer;
22

3-
public class Practice4 {
3+
public class DoublePointerTwo {
44

5-
/**
5+
/** move zero
66
*
77
* [1, 3 ,0 ,4 ,0 ,2, 5] => [1,3,4,2,5,0,0]
88
* require in-place sort

src/main/java/com/leetcode/Practice1.java renamed to src/main/java/com/leetcode/dynamicplan/DynPlanOne.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package com.leetcode;
1+
package com.leetcode.dynamicplan;
22

33
import java.io.IOException;
44
import java.util.Scanner;
55

66

77
/**
8-
*
9-
* fibonacci sequence / go upstairs 1/2 steps
8+
* name: Climbing Stairs
9+
* fibonacci sequence
1010
*/
11-
public class Practice1 {
11+
public class DynPlanOne {
1212

1313
public static int fibonacci(int n) {
1414
if (n == 1) {

src/main/java/com/leetcode/Practice2.java renamed to src/main/java/com/leetcode/hash/HashOne.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
package com.leetcode;
2-
3-
import java.util.Arrays;
1+
package com.leetcode.hash;
42

53
/**
6-
*
7-
* arr = [2 , 7, 9 , 11 ] , target number 9
8-
* arr[0] + arr[1] = 9
4+
* two sum
5+
* arr = [2 , 7, 9 , 11 ] , target number 9
6+
* arr[0] + arr[1] = 9
97
*/
108

11-
public class Practice2 {
12-
9+
public class HashOne {
1310

1411

1512
public static void main(String[] args) {
@@ -19,32 +16,31 @@ public static void main(String[] args) {
1916
// the other one loop the array from smallest to largest , test the sum equals to the target number or not,
2017
//if the sum is greater than target number , then break the current loop.
2118
int target = 9;
22-
int[] arr = {2,7,9,11};
19+
int[] arr = {2, 7, 9, 11};
2320

2421
int[] newarr = new int[arr.length];
25-
for (int i =0 , j = 0 ; i < arr.length ; i ++){
26-
if(target > arr[i]){
22+
for (int i = 0, j = 0; i < arr.length; i++) {
23+
if (target > arr[i]) {
2724
newarr[j] = arr[i];
2825
j++;
2926
}
3027
}
3128
System.out.println(newarr.length);
3229

33-
for(int i = newarr.length -1 ; i > 0 ; i --){
34-
for(int j = 0; j < newarr.length; j ++){
35-
if(newarr[i] + newarr[j] == target){
30+
for (int i = newarr.length - 1; i > 0; i--) {
31+
for (int j = 0; j < newarr.length; j++) {
32+
if (newarr[i] + newarr[j] == target) {
3633

3734
System.out.println("Found the index : " + i + " and " + j);
3835
System.exit(0);
39-
}else if (newarr[i] + newarr[j] > target){
36+
} else if (newarr[i] + newarr[j] > target) {
4037
break;
4138
}
4239

4340
}
4441
}
4542

4643

47-
4844
}
4945
}
5046

src/main/java/com/leetcode/Practice9.java renamed to src/main/java/com/leetcode/linkedlist/LinkedListOne.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package com.leetcode;
1+
package com.leetcode.linkedlist;
22

33
import com.leetcode.util.ListNode;
44
import com.leetcode.util.Utils;
55

66
/**
7-
* intersect list
7+
* name: two intersect list
88
*/
9-
public class Practice9 {
9+
public class LinkedListOne {
1010

1111

1212
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
@@ -42,7 +42,7 @@ public static void main(String[] args) {
4242
int[] listB = {5, 6, 1, 8, 4, 5};
4343

4444
// expect : int intersectVal = 8;
45-
Practice9 practice9 = new Practice9();
45+
LinkedListOne practice9 = new LinkedListOne();
4646
practice9.listAHead = Utils.buildList(listA);
4747
practice9.listBHead = Utils.buildList(listB );
4848
ListNode intersectionNode = practice9.getIntersectionNode(practice9.listAHead, practice9.listBHead);

0 commit comments

Comments
 (0)