public static void quickSort(int[] array) {
quickSort(array, 0, array.length - 1);
}
private static void quickSort(int[] arr, int begin, int end) {
if (begin < end) {
int partitionIndex = partition(arr, begin, end);
quickSort(arr, begin, partitionIndex - 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
private int hammingWeight(int x) { | |
int result = 0; | |
while (x > 0) { | |
x = x & (x - 1); | |
result++; | |
} | |
return result; | |
} |
private int kmpIndex(String string, String pattern) {
int[] patternPrefix = patternPrefixArray(pattern);
for (int t = 0, p = 0 ; t < string.length() && p < pattern.length() ; ) {
if (string.charAt(t) == pattern.charAt(p)) {
if (p == pattern.length() - 1) return t - p;
p++;
It seems like Binary Search is actually just a single algorithm, when that is absolutely not the case at all. There are several different variants of Binary Search all giving a different kind of target value. One that gives rightmost, another that ives leftmost, one which gives the first largest than target etc.
public char nextGreatestLetter(char[] letters, char target) {
int left = 0, right = letters.length - 1, middle;
while (left <= right) {
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
array = [[0 for i in range(columns)] for j in range(rows)] |
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
var https = require('https'), | |
user = process.argv[2], | |
opts = parseOpts(process.argv.slice(3)) | |
request('/users/' + user, function (res) { | |
if (!res.public_repos) { | |
console.log(res.message) | |
return | |
} | |
var pages = Math.ceil(res.public_repos / 100), |
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
$ pip install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py3-none-any.whl |
NewerOlder