forked from rbmonster/learning-note
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
698 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/learning/algorithm/greedy/ChildCookies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.learning.algorithm.greedy; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* <pre> | ||
* @Description: | ||
* | ||
* </pre> | ||
* | ||
* @version v1.0 | ||
* @ClassName: ChildCookies | ||
* @Author: sanwu | ||
* @Date: 2021/1/24 16:21 | ||
*/ | ||
public class ChildCookies { | ||
|
||
public int findContentChildren(int[] g, int[] s) { | ||
Arrays.sort(g); | ||
Arrays.sort(s); | ||
int i = 0, j = 0; | ||
int len1 = g.length; | ||
int len2 = s.length; | ||
while(i < len1 && j < len2) { | ||
if(g[i] <= s[j]){ | ||
i++; | ||
} | ||
j++; | ||
} | ||
return i; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/learning/algorithm/greedy/FindMinArrowShots.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.learning.algorithm.greedy; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* <pre> | ||
* @Description: | ||
* | ||
* </pre> | ||
* | ||
* @version v1.0 | ||
* @ClassName: FindMinArrowShots | ||
* @Author: sanwu | ||
* @Date: 2021/1/24 17:06 | ||
*/ | ||
public class FindMinArrowShots { | ||
|
||
public static void main(String[] args) { | ||
int[][] point = new int[][] {{9,12},{1,10},{4,11},{8,12},{3,9},{6,9},{6,7}}; | ||
new FindMinArrowShots().findMinArrowShots(point); | ||
} | ||
|
||
public int findMinArrowShots(int[][] points) { | ||
if(points == null || points.length == 0) { | ||
return 0; | ||
} | ||
Arrays.sort(points, (o1, o2)-> o1[1]<=o2[1]? -1: 1); | ||
int end = points[0][1]; | ||
int res = 1; | ||
for(int i = 1; i< points.length; i++) { | ||
if(end >= points[i][0]) { | ||
continue; | ||
} | ||
end = points[i][1]; | ||
res++; | ||
} | ||
return res; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/learning/algorithm/greedy/NoRepeatSeq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.learning.algorithm.greedy; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* <pre> | ||
* @Description: | ||
* | ||
* </pre> | ||
* | ||
* @version v1.0 | ||
* @ClassName: NoRepeatSeq | ||
* @Author: sanwu | ||
* @Date: 2021/1/24 16:40 | ||
*/ | ||
public class NoRepeatSeq { | ||
|
||
public static void main(String[] args) { | ||
int[][] intervals = new int[][] {{1,100},{11,22},{1,11},{2,12}}; | ||
new NoRepeatSeq().eraseOverlapIntervals(intervals); | ||
} | ||
|
||
public int eraseOverlapIntervals(int[][] intervals) { | ||
if(intervals == null || intervals.length ==0) { | ||
return 0; | ||
} | ||
Arrays.sort(intervals, (o1, o2) -> o1[1]<=o2[1] ? -1: 1); | ||
int end = intervals[0][1]; | ||
int remove = 0; | ||
for (int i = 1; i < intervals.length; i++) { | ||
if (end<=intervals[i][0]){ | ||
end = intervals[i][1]; | ||
} else { | ||
remove++; | ||
} | ||
} | ||
return remove; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/learning/basic/java/basictest/Chicken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.learning.basic.java.basictest; | ||
|
||
/** | ||
* <pre> | ||
* @Description: | ||
* | ||
* </pre> | ||
* | ||
* @version v1.0 | ||
* @ClassName: Chicken | ||
* @Author: sanwu | ||
* @Date: 2021/1/27 10:36 | ||
*/ | ||
public class Chicken extends Food { | ||
|
||
@Override | ||
public Food cook() { | ||
Food food = new Chicken(); | ||
return food; | ||
} | ||
|
||
public static void main(String[] args) { | ||
new Chicken().cook(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.learning.basic.java.basictest; | ||
|
||
import lombok.Data; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* <pre> | ||
* @Description: | ||
* | ||
* </pre> | ||
* | ||
* @version v1.0 | ||
* @ClassName: Food | ||
* @Author: sanwu | ||
* @Date: 2021/1/27 10:35 | ||
*/ | ||
@Slf4j | ||
@Data | ||
public class Food { | ||
|
||
private String name; | ||
private int id; | ||
|
||
public Food cook() { | ||
log.info("this is food cook"); | ||
return new Food(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.