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 Solution | |
{ | |
public double FindMedianSortedArrays(int[] A, int[] B) | |
{ | |
if (Object.ReferenceEquals(A, null) || Object.ReferenceEquals(B, null)) | |
{ | |
throw new ArgumentNullException(); | |
} | |
int aLen = A.Length; |
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 Solution | |
{ | |
public double FindMedianSortedArrays(int[] A, int[] B) | |
{ | |
if (Object.ReferenceEquals(A, null) || Object.ReferenceEquals(B, null)) | |
{ | |
throw new ArgumentNullException(); | |
} | |
int aLen = A.Length; |
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 double FindMedianSortedArrays(int[] A, int[] B) | |
{ | |
// TODO: Check for corner cases | |
int aLen = A.Length; | |
int bLen = B.Length; | |
int leftHalfLen = GetLeftHalfLength(aLen + bLen); | |
// aMinCount and aMaxCount are the min and max number | |
// of values A can contribute to the left half of A ∪ B, |
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
Tests run: 279, Failures: 2, Errors: 0, Skipped: 236, Time elapsed: 17.924 sec <<< FAILURE! - in TestSuite | |
setUp(com.github.shyiko.mysql.binlog.BinaryLogClientGTIDIntegrationTest) Time elapsed: 0.759 sec <<< FAILURE! | |
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure | |
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. | |
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) | |
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) | |
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) | |
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) | |
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) |
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
// | |
// Finds the position of the smallest element in a cyclically sorted array. | |
// Copied verbatim from: http://elementsofprogramminginterviews.com/solutions/java/BinarySearchCircularArray.java | |
// | |
public static int searchSmallest(List<Integer> A) { | |
int left = 0, right = A.size() - 1; | |
while (left < right) { | |
int mid = left + ((right - left) / 2); | |
if (A.get(mid) > A.get(right)) { | |
// Minimum must be in A.subList(mid + 1, right + 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 static int binarySearch0(int[] a, int fromIndex, int toIndex, int key) { | |
int low = fromIndex; | |
int high = toIndex - 1; | |
while (low <= high) { | |
int mid = (low + high) >>> 1; | |
int midVal = a[mid]; | |
if (midVal < key) | |
low = mid + 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
#include <string> | |
#include <fstream> | |
int main() { | |
std::ifstream input_file("/etc/passwd"); | |
if (input_file) | |
{ | |
std::string line; |
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
tree_node* insert(tree_node* n, int value) | |
{ | |
if (n == NULL) | |
{ | |
tree_node* new_node = new tree_node(); | |
new_node->data = value; | |
new_node->left = new_node->right = NULL; | |
return new_node; | |
} |
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
tree_node* insert(tree_node* n, int value) | |
{ | |
if (n == NULL) | |
{ | |
return NULL; | |
} | |
tree_node* x_parent = NULL; | |
tree_node* x = n; |
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
tree_node* insert(tree_node* n, int value) | |
{ | |
if (n == NULL) | |
{ | |
return NULL; | |
} | |
tree_node** x = &n; | |
while ((*x) != NULL) |
NewerOlder