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
private static void findTopN(int[] a, int k) { | |
if (a == null) return; | |
if (a.length <= k) { | |
return; | |
} | |
PriorityQueue<Integer> pq = new PriorityQueue<Integer> (k); | |
for (int i = 0; i < a.length; i++) { | |
pq.add(a[i]); | |
if (pq.size() > k) { | |
pq.poll(); |
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
public static void findFirstSeq(int[] a, int k) { | |
int size = a.length; | |
for (int i = 0; i < size; i++) { | |
int total = 0; | |
for (int j = i; j < size; j++) { | |
total += a[j]; | |
if (total > k) { | |
break; | |
} else if (total == k) { | |
System.out.println("FOUND IT " + a[i] + ", " + a[j]); |
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
public static void removeDuplicates(int[] a){ | |
Set<Integer> s = new HashSet<Integer>(); | |
for (int i : a) { | |
s.add(i); | |
} | |
s.toArray(); | |
} |
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
public static void permString(String p, String t){ | |
int size = t.length(); | |
if (size == 0){ | |
System.out.println(p); | |
} else { | |
for (int i=0; i<size; i++){ | |
perm(p + t.charAt(i), | |
t.substring(0,i) + t.substring(i+1)); | |
} | |
} |
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
public static void findTopK(int[] a, int k){ | |
PriorityQueue<Integer> pq = new PriorityQueue<Integer>(k+1); | |
for (int i : a){ | |
if (!pq.contains(i)){ | |
pq.add(i); | |
} | |
if (pq.size() > k){ | |
pq.poll(); | |
} | |
} |
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
public static File findFile(File file, String fileName){ | |
File[] files = file.listFiles(); | |
if (files == null) return null; | |
for (File f : files){ | |
if (f.isFile() && f.getName().equals(fileName)){ | |
return f; | |
} else if (f.isDirectory()){ | |
return findFile(f, fileName); | |
} | |
} |
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
$.ajax({ | |
type: "POST", | |
url: "file_upload.php", | |
data: yourData, | |
dataType: "json", | |
success: function (result) { | |
if (result.success) { | |
//your cod | |
} | |
}, |
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
// Slide up animation | |
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > | |
<translate | |
android:duration="@android:integer/config_mediumAnimTime" | |
android:fromYDelta="100%" | |
android:interpolator="@android:anim/accelerate_interpolator" | |
android:toXDelta="0" /> |
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
public static int sqr(int a){ | |
if (a < 1) return 0; | |
int low = 1; | |
int h = a; | |
while (low < h){ | |
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
public class HelloWorld { | |
public static void main(String[] args) { | |
Node r = new Node(0); | |
r.left = new Node(1); | |
r.right = new Node(2); | |
r.left.left = new Node(3); | |
r.left.right = new Node(4); |