This file contains hidden or 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
| package cormen; | |
| public interface BinaryTree<Key extends Comparable> { | |
| Key next(Key key); | |
| Key previous(Key key); | |
| Key max(); |
This file contains hidden or 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
| /** | |
| * Definition for binary tree | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } | |
| * } | |
| */ | |
| public class Solution { |
This file contains hidden or 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
| /** | |
| * 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) { |
This file contains hidden or 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 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++) { |
This file contains hidden or 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
| 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 = { |
This file contains hidden or 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 boolean isNumber(String s) { | |
| if (s == null) return false; | |
| s = s.trim(); | |
| if (s.length() == 0) return false; | |
| s = s+ ' '; | |
| State state = State.INIT; |
This file contains hidden or 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 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; | |
This file contains hidden or 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 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) { |
This file contains hidden or 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 { | |
| 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) }; | |
| } | |
This file contains hidden or 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 LRUCache { | |
| Node head; | |
| int capacity; | |
| class Node { | |
| int key; | |
| int value; | |
| Node prev; | |
| Node next; |
OlderNewer