Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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:master
base:master
Choose a base branch
Loading
fromsinglemancombat:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
66 commits
Select commitHold shift + click to select a range
bd11ddf
KthSort
yuzhangcmuSep 23, 2014
841e167
add the demos
yuzhangcmuSep 23, 2014
dabfdb7
min cut
yuzhangcmuSep 25, 2014
762dcad
Create README.md
yuzhangcmuSep 25, 2014
ce3384e
Update README.md
yuzhangcmuSep 25, 2014
078baa7
modify the directors
yuzhangcmuSep 26, 2014
ab453fc
move the folder.
yuzhangcmuSep 26, 2014
af5edeb
modify the tree Demo
yuzhangcmuSep 26, 2014
52407ba
The LCA problem.
yuzhangcmuSep 26, 2014
7c9819f
add some comments.
yuzhangcmuSep 26, 2014
bb3eb2b
Arrange the code.
yuzhangcmuSep 27, 2014
fa314c2
merge Sort
yuzhangcmuSep 28, 2014
37c4105
merge
yuzhangcmuOct 2, 2014
b0e4e32
Five Chessman
yuzhangcmuOct 2, 2014
441dba7
FiveChessman
yuzhangcmuOct 2, 2014
2eec824
notes
yuzhangcmuOct 2, 2014
1551e7f
the largest Common subtree
yuzhangcmuOct 2, 2014
61e79b2
the largest common
yuzhangcmuOct 2, 2014
ff798ae
largestCommon
yuzhangcmuOct 2, 2014
718698d
TestPermutation
yuzhangcmuOct 5, 2014
7d60ff4
isCompleteBinaryTree
yuzhangcmuOct 5, 2014
c73a8a7
NextPermutation
yuzhangcmuOct 5, 2014
8c9f0e8
permutation sequence
yuzhangcmuOct 5, 2014
b8c8f5f
Fibonacci
yuzhangcmuOct 5, 2014
92f4168
add new file
Oct 7, 2014
f928b91
add code.
Oct 7, 2014
b6817a6
Recover Binary Search Tree
yuzhangcmuOct 8, 2014
a758230
isValidBST
yuzhangcmuOct 8, 2014
c04d009
in order
yuzhangcmuOct 8, 2014
3292319
tree
yuzhangcmuOct 8, 2014
8f28a48
tree
yuzhangcmuOct 8, 2014
2d0cf85
minDepth
yuzhangcmuOct 8, 2014
dc15508
min
yuzhangcmuOct 8, 2014
de48d99
facebook
yuzhangcmuOct 8, 2014
72f914d
Unique BSTs
yuzhangcmuOct 9, 2014
d92fcd1
tree2
yuzhangcmuOct 9, 2014
632666f
merge Sort
yuzhangcmuOct 9, 2014
d1c27bd
merge
yuzhangcmuOct 9, 2014
ec77e43
remove duplicate
yuzhangcmuOct 9, 2014
127db30
remove duplicates2
yuzhangcmuOct 9, 2014
63dd8d0
array
yuzhangcmuOct 9, 2014
23f07e3
search
yuzhangcmuOct 9, 2014
bd02708
maxSubArray
yuzhangcmuOct 9, 2014
88a4d50
the merge
yuzhangcmuOct 9, 2014
0ccff33
strstr
yuzhangcmuOct 10, 2014
096b743
list
yuzhangcmuOct 10, 2014
d955d59
divide
yuzhangcmuOct 10, 2014
218d63f
pow
yuzhangcmuOct 10, 2014
4f99b2d
pow
yuzhangcmuOct 10, 2014
7564463
list
yuzhangcmuOct 10, 2014
1ddacc5
sort
yuzhangcmuOct 10, 2014
d5573fc
reorder list
yuzhangcmuOct 10, 2014
c144ac6
random
yuzhangcmuOct 10, 2014
2a37fec
reverse2
yuzhangcmuOct 10, 2014
150f920
tree
yuzhangcmuOct 10, 2014
82143ad
name
yuzhangcmuOct 10, 2014
f08140a
lett
yuzhangcmuOct 11, 2014
42796c9
list
yuzhangcmuOct 11, 2014
d6d1308
list
yuzhangcmuOct 11, 2014
0060c07
rotate
yuzhangcmuOct 11, 2014
72e5ddf
list
yuzhangcmuOct 11, 2014
cfdbfe8
remove
yuzhangcmuOct 11, 2014
732d38a
list
yuzhangcmuOct 11, 2014
53f429f
tree
yuzhangcmuOct 11, 2014
1693ac2
candy
yuzhangcmuOct 11, 2014
7a80b46
combine
yuzhangcmuOct 11, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletionsDivide2/Pow.java
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
package Algorithms;
import java.util.Stack;

import Algorithms.tree.TreeNode;



public class Flatten {
Expand Down
103 changes: 103 additions & 0 deletionsGraphDemo.java
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,8 @@
import java.util.ArrayList;
import java.util.Stack;

import Algorithms.tree.TreeNode;


public class InOrderTraversal {
public ArrayList<Integer> inorderTraversal(TreeNode root) {
Expand Down
2 changes: 2 additions & 0 deletionsIsSymmetric.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,8 @@

import java.util.ArrayDeque;

import Algorithms.tree.TreeNode;

public class IsSymmetric {
public boolean isSymmetric(TreeNode root) {
if (root == null) {
Expand Down
43 changes: 43 additions & 0 deletionsKthSort.java
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,11 +57,15 @@ public static void main(String[] args) {
ListNode c1 = new ListNode(1);
ListNode c2 = new ListNode(12);
c1.next = c2;
c2.next = n1;
//c2.next = n1;

//ListNode mergeNode = mergeSortedListRec(m1, c1);
ListNode mergeNode = mergeLink(m1, c1);
//ListNode mergeNode2 = mergeLink(m1, c1);
//ListNode mergeNode = mergeSortedList(m1, c1);
//printList(mergeNode);
printList(mergeNode);
//printList(mergeNode2);

System.out.println();

n1.next = n2;
n2.next = n3;
Expand DownExpand Up@@ -433,6 +437,42 @@ public static ListNode mergeSortedList(ListNode head1, ListNode head2) {
return dummyNode.next;
}

static class Node {
Node next;
int val;
Node (int val) {
this.val = val;
}
}

public static ListNode mergeLink (ListNode aLink, ListNode bLink) {
ListNode dummy = new ListNode(0);

ListNode root = dummy;

while (aLink != null && bLink != null) {
if (aLink.val < bLink.val) {
dummy.next = aLink;
dummy = aLink;
aLink = aLink.next;

} else {
dummy.next = bLink;
dummy = bLink;
bLink = bLink.next;

}
}

if (aLink != null) {
dummy.next = aLink;
} else {
dummy.next = bLink;
}

return root.next;
}

/*
* 先完成的算法,应该会简单一点儿。
* 简直是优雅的算法啊!太棒了!只不过 为什么自己很难想出这么棒的算法呢?
Expand Down
2 changes: 2 additions & 0 deletionsMax_path_BinaryTree.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
package Algorithms;
import java.util.ArrayList;

import Algorithms.tree.TreeNode;


public class Max_path_BinaryTree {
public static void main(String args[]){
Expand Down
3 changes: 3 additions & 0 deletionsPopulate2.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
package Algorithms;

import Algorithms.tree.TreeLinkNode;

public class Populate2 {
public static void main(String[] args) {
TreeLinkNode root = new TreeLinkNode(2);
Expand Down
94 changes: 0 additions & 94 deletionsPostOrder.java
View file
Open in desktop

This file was deleted.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp