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
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
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 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
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 int getMin(int[] a) { | |
if (a == null) { | |
return 0; | |
} | |
if (a.length == 1) { | |
return a[0]; | |
} | |
int min = a[0]; | |
for (int i = 0; i < a.length; i++) { | |
if (a[i] < min) { |
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 getMinValue(int[] a) { | |
if (a == null) | |
return -1; | |
int lo = 0; | |
int hi = a.length - 1; | |
while (lo <= hi) { | |
int mid = lo + (hi - lo) / 2; | |
if (a[mid] > a[hi]) { | |
lo = mid + 1; | |
} else if (a[mid] < a[hi]) { |
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 boolean checkIfAnagram(String s1, String s2) { | |
int len1 = s1.length(); | |
for (int i = 0; i < len1; i++) { | |
if (s1.charAt(i) != s2.charAt(len1 - i - 1)) { | |
return false; | |
} | |
} | |
return true; | |
} |