Skip to content

Instantly share code, notes, and snippets.

/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public class LRUCache {
Node head;
int capacity;
class Node {
int key;
int value;
Node prev;
Node next;
public class Solution {
int[] A;
int target;
public int[] searchRange(int[] A, int target) {
this.A = A;
this.target = target;
int s = find0();
return new int[]{s, (s==-1) ? -1: find1(s) };
}
public class Solution {
public int search(int[] A, int target) {
int res = -1;
if (A != null && A.length > 0) {
int s = 0, e = A.length-1;
int mid = 0;
while (s < e) {
mid = (s+e) >>> 1;
if (A[mid] == target) {
public class Solution {
public int sqrt(int x) {
int s = 1, e = x, res = x;
int max_res = (int)Math.pow(2, 16);
while (s < e) {
int mid = (s + e) >>> 1;
int sqr = mid * mid;
res = mid;
public class Solution {
public boolean isNumber(String s) {
if (s == null) return false;
s = s.trim();
if (s.length() == 0) return false;
s = s+ ' ';
State state = State.INIT;
package leetcode;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;
public class Solution {
public static void main(String[] args) {
int[][] matrix = {
public class Solution {
public int maxElementPath(int[][] matrix) {
int res = 0;
if (matrix != null) {
int height = matrix.length;
int width = height > 0 ? matrix[0].length : 0;
for (int i = 0; i < height; i++) {
/**
* Maximum Subarray
* Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
* <p/>
* For example, given the array [−2,1,−3,4,−1,2,1,−5,4],
* the contiguous subarray [4,−1,2,1] has the largest sum = 6.
* https://oj.leetcode.com/problems/maximum-subarray/
*/
public class Solution {
public int maxSubArray(int[] arr) {
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {