- Notifications
You must be signed in to change notification settings - Fork117
Merge latest updates#1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
singlemancombat wants to merge66 commits intorpj911:masterChoose a base branch fromsinglemancombat:master
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
66 commits Select commitHold shift + click to select a range
bd11ddf
KthSort
yuzhangcmu841e167
add the demos
yuzhangcmudabfdb7
min cut
yuzhangcmu762dcad
Create README.md
yuzhangcmuce3384e
Update README.md
yuzhangcmu078baa7
modify the directors
yuzhangcmuab453fc
move the folder.
yuzhangcmuaf5edeb
modify the tree Demo
yuzhangcmu52407ba
The LCA problem.
yuzhangcmu7c9819f
add some comments.
yuzhangcmubb3eb2b
Arrange the code.
yuzhangcmufa314c2
merge Sort
yuzhangcmu37c4105
merge
yuzhangcmub0e4e32
Five Chessman
yuzhangcmu441dba7
FiveChessman
yuzhangcmu2eec824
notes
yuzhangcmu1551e7f
the largest Common subtree
yuzhangcmu61e79b2
the largest common
yuzhangcmuff798ae
largestCommon
yuzhangcmu718698d
TestPermutation
yuzhangcmu7d60ff4
isCompleteBinaryTree
yuzhangcmuc73a8a7
NextPermutation
yuzhangcmu8c9f0e8
permutation sequence
yuzhangcmub8c8f5f
Fibonacci
yuzhangcmu92f4168
add new file
f928b91
add code.
b6817a6
Recover Binary Search Tree
yuzhangcmua758230
isValidBST
yuzhangcmuc04d009
in order
yuzhangcmu3292319
tree
yuzhangcmu8f28a48
tree
yuzhangcmu2d0cf85
minDepth
yuzhangcmudc15508
min
yuzhangcmude48d99
facebook
yuzhangcmu72f914d
Unique BSTs
yuzhangcmud92fcd1
tree2
yuzhangcmu632666f
merge Sort
yuzhangcmud1c27bd
merge
yuzhangcmuec77e43
remove duplicate
yuzhangcmu127db30
remove duplicates2
yuzhangcmu63dd8d0
array
yuzhangcmu23f07e3
search
yuzhangcmubd02708
maxSubArray
yuzhangcmu88a4d50
the merge
yuzhangcmu0ccff33
strstr
yuzhangcmu096b743
list
yuzhangcmud955d59
divide
yuzhangcmu218d63f
pow
yuzhangcmu4f99b2d
pow
yuzhangcmu7564463
list
yuzhangcmu1ddacc5
sort
yuzhangcmud5573fc
reorder list
yuzhangcmuc144ac6
random
yuzhangcmu2a37fec
reverse2
yuzhangcmu150f920
tree
yuzhangcmu82143ad
name
yuzhangcmuf08140a
lett
yuzhangcmu42796c9
list
yuzhangcmud6d1308
list
yuzhangcmu0060c07
rotate
yuzhangcmu72e5ddf
list
yuzhangcmucfdbfe8
remove
yuzhangcmu732d38a
list
yuzhangcmu53f429f
tree
yuzhangcmu1693ac2
candy
yuzhangcmu7a80b46
combine
yuzhangcmuFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletionsDivide2/Pow.java
This file contains hidden or 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,38 @@ | ||
package Algorithms.Divide2; | ||
public class Pow { | ||
public static void main(String[] strs) { | ||
System.out.println(pow(-3, -2147483648)); | ||
} | ||
public static double pow(double x, int n) { | ||
if (x == 0) { | ||
return 0; | ||
} | ||
if (x == 1 || n == 0) { | ||
return 1; | ||
} | ||
// Because when we deal with -2147483648, we can't get right -n | ||
// cause -n == n when it is -2147483648. | ||
// 注意 这样写是不行的,因为-n在n到最小值会出错, | ||
// int的最小值(负数)取-n仍然是n 这样就错了。 | ||
if (n < 0) { | ||
double ret1 = x * pow(x, -(1 + n)); | ||
return 1/(double)ret1; | ||
} | ||
int m = n%2; | ||
// count | ||
double ret = pow(x, n/2); | ||
ret *= ret; | ||
if (m == 1) { | ||
ret *= x; | ||
} | ||
return ret; | ||
} | ||
} |
2 changes: 2 additions & 0 deletionsFlatten.java
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package Algorithms; | ||
import java.util.Stack; | ||
import Algorithms.tree.TreeNode; | ||
public class Flatten { | ||
103 changes: 103 additions & 0 deletionsGraphDemo.java
This file contains hidden or 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,103 @@ | ||
package Algorithms; | ||
import java.util.ArrayList; | ||
public class GraphDemo { | ||
private static int M = Integer.MAX_VALUE; // 表示此路不可通 | ||
// http://www.geeksforgeeks.org/greedy-algorithms-set-6-dijkstras-shortest-path-algorithm/ | ||
// 以上为不能再优美的C语言实现。 | ||
public static void main(String[] args) { | ||
int[][] w = { // 用邻接表矩阵表示的无向图 | ||
{0, 3, 2000, 7, M}, | ||
{3, 0, 4, 2, M}, | ||
{M, 4, 0, 5, 4}, | ||
{7, 2, 5, 0, 6}, | ||
{M, M , 4, 6, 0} | ||
}; | ||
int[][] w2 = { // 用邻接表矩阵表示的无向图 | ||
{0, 10, M, 30, 100}, | ||
{M, 0, 50, M, M}, | ||
{M, M, 0, M, 10}, | ||
{M, M, 20, 0, 60}, | ||
{M, M, M, M, 0} | ||
}; | ||
int start = 0; | ||
int[] shortPath = dijkstra(w2, start); | ||
for (int i = 0; i < shortPath.length; i++) { | ||
System.out.println("The shortest path length from start to " + i + " is:" + shortPath[i]); | ||
} | ||
} | ||
public static int[] dijkstra(int[][] graph, int src) { | ||
if (graph == null || graph.length == 0 || graph[0].length == 0) { | ||
return null; | ||
} | ||
// get to know the number of the vertexs. | ||
int v = graph.length; | ||
// We need a indicator to know if we have visited the vertex. | ||
boolean visit[] = new boolean[v]; | ||
// record the length result. | ||
int[] pathLen = new int[v]; | ||
// record the path. | ||
ArrayList<ArrayList<Integer>> path = new ArrayList<ArrayList<Integer>>(); | ||
for (int i = 0; i < v; i++) { | ||
path.add(new ArrayList<Integer>()); | ||
path.get(i).add(0); | ||
path.get(i).add(i); | ||
} | ||
// setup the source vertex; | ||
visit[0] = true; | ||
pathLen[0] = 0; | ||
// stop when all the vertices has been added into the result set. | ||
for (int i = 0; i < v - 1; i++) { | ||
int minLen = M; | ||
int minIndex = -1; | ||
for (int j = 0; j < v; j++) { | ||
// sometimes there is no route, so just let equal also return. | ||
// so we use graph[src][j] <= minLen | ||
if (!visit[j] && graph[src][j] <= minLen) { | ||
minLen = graph[src][j]; | ||
minIndex = j; | ||
} | ||
} | ||
// get the new shortest path, add it into the solution set. | ||
visit[minIndex] = true; | ||
pathLen[minIndex] = graph[src][minIndex]; | ||
// update all the neighbors of the new vertex. | ||
for (int k = 0; k < v; k++) { | ||
// if the path which pass the minIndex is shorter than the former path, | ||
// just update it. | ||
if (!visit[k] | ||
&& graph[src][minIndex] != M | ||
&& graph[minIndex][k] != M | ||
&& graph[src][minIndex] + graph[minIndex][k] < graph[src][k]) { | ||
graph[src][k] = graph[src][minIndex] + graph[minIndex][k]; | ||
path.set(k, new ArrayList<Integer>(path.get(minIndex))); | ||
path.get(k).add(k); | ||
} | ||
} | ||
} | ||
for (ArrayList<Integer> array: path) { | ||
System.out.println(array.toString()); | ||
} | ||
return pathLen; | ||
} | ||
} |
2 changes: 2 additions & 0 deletionsInOrderTraversal.java
This file contains hidden or 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
2 changes: 2 additions & 0 deletionsIsSymmetric.java
This file contains hidden or 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
43 changes: 43 additions & 0 deletionsKthSort.java
This file contains hidden or 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,43 @@ | ||
packageAlgorithms; | ||
importjava.util.HashMap; | ||
publicclassKthSort { | ||
publicstaticclassGraph { | ||
Stringname; | ||
HashMap<Graph,Integer>subs; | ||
publicGraph(Stringname) { | ||
this.name =name; | ||
} | ||
} | ||
publicstaticvoidmain(String[]strs) { | ||
// int[] input = new int[]{1,2,4,3,9,11,0}; | ||
// sort(input); | ||
// for(int n: input) { | ||
// System.out.print(n + " "); | ||
// } | ||
Graphc1 =newGraph("c1"); | ||
//for() | ||
} | ||
publicstaticvoidsort(int[]input) { | ||
if (input ==null) { | ||
return; | ||
} | ||
intlen =input.length; | ||
for (inti =1;i <len;i++) { | ||
intcur =input[i]; | ||
intj =i -1; | ||
while (j >=0 &&input[j] >cur) { | ||
input[j +1] =input[j]; | ||
j--; | ||
} | ||
input[j +1] =cur; | ||
} | ||
} | ||
} |
46 changes: 43 additions & 3 deletionsListNodeDemo.java
This file contains hidden or 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
2 changes: 2 additions & 0 deletionsMax_path_BinaryTree.java
This file contains hidden or 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
3 changes: 3 additions & 0 deletionsPopulate2.java
This file contains hidden or 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
94 changes: 0 additions & 94 deletionsPostOrder.java
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.