- 博客(216)
- 收藏
- 关注
原创 Leetcode#76||Minimum Window Substring
public class Solution { public String minWindow(String s, String t) { String result = ""; if (s == null || t == null || s.length() < t.length()) { return resul
2015-08-19 16:51:15
366
原创 Leetcode#75||Sort Colors
public class Solution { public void sortColors(int[] nums) { if (nums == null || nums.length < 2) { return; } int length = nums.length;
2015-08-19 14:03:30
335
原创 Leetcode#74||Search a 2D Matrix
public class Solution { public boolean searchMatrix(int[][] matrix, int target) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return false; }
2015-08-19 07:55:22
338
原创 Leetcode#73||Set Matrix Zeroes
public class Solution { public void setZeroes(int[][] matrix) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return; } int row
2015-08-18 18:17:18
450
原创 Leetcode#72||Edit Distance
public class Solution { public int minDistance(String word1, String word2) { int m = word1.length(); int n = word2.length(); int[][] dist = new int[m + 1][n + 1];
2015-08-18 18:05:44
261
原创 Leetcode#70||Climbing Stairs
public class Solution { public int climbStairs(int n) { if (n <= 0) { return 0; } else if (n == 1) { return 1; } int i = 1;
2015-08-18 15:44:09
303
原创 Leetcode#69||Sqrt(x)
public class Solution { public int mySqrt(int x) { if (x < 0) { return -1; } int left = 1; int right = x; while (left <= right
2015-08-18 15:36:59
268
原创 Leetcode#67||Add Binary
public class Solution { public String addBinary(String a, String b) { if (a.length() < b.length()) { String temp = a; a = b; b = temp; }
2015-08-18 15:20:34
277
原创 Leetcode#66||Plus One
public class Solution { public int[] plusOne(int[] digits) { if (digits == null || digits.length == 0) { return digits; } int carry = 1;
2015-08-18 14:54:28
292
原创 Leetcode#65||Valid Number
public class Solution { public boolean isNumber(String s) { int length = s.length(); int i = 0; int e = length - 1; while (i < length && Character
2015-08-18 14:47:35
381
原创 Leetcode#64||Minimum Path Sum
public class Solution { public int minPathSum(int[][] grid) { if (grid == null || grid.length == 0 || grid[0].length == 0) { return -1; } int m = grid.
2015-08-18 11:32:37
278
原创 Leetcode#63||Unique Paths II
public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { if (obstacleGrid == null || obstacleGrid.length == 0 || obstacleGrid[0].length ==0) { return
2015-08-18 11:23:30
241
原创 Leetcode#62||Unique Paths
public class Solution { public int uniquePaths(int m, int n) { if (m < 1 || n < 1) { return 0; } int[] paths = new int[n]; for (int j
2015-08-18 11:13:34
306
原创 Leetcode#61||Rotate List
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode rota
2015-08-18 11:08:55
309
原创 Leetcode#60||Permutation Sequence
public class Solution { public String getPermutation(int n, int k) { StringBuilder result = new StringBuilder(); List list = new ArrayList(); int factorial = 1;
2015-08-18 10:59:01
343
原创 Leetcode#59||Spiral Matrix II
public class Solution { public int[][] generateMatrix(int n) { int[][] result = new int[n][n]; int t= 0; int cnt = 1; while (t < n / 2) {
2015-08-17 18:14:04
311
原创 Leetcode#58||Length of Last Word
public class Solution { public int lengthOfLastWord(String s) { if (s == null || s.length() == 0) { return 0; } int result = 0; char[]
2015-08-17 15:50:54
280
原创 Leetcode#57||Insert Interval
/** * Definition for an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int e) { start = s; end = e; } * } */
2015-08-17 15:42:29
258
原创 Leetcode#56||Merger Intervals
/** * Definition for an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int e) { start = s; end = e; } * } */
2015-08-17 15:09:16
240
原创 Leetcode#55||Jump Game
public class Solution { public boolean canJump(int[] nums) { if (nums == null || nums.length == 0) { return false; } int maxRange = 0;
2015-08-17 14:51:24
441
原创 Leetcode#54||Spiral Matrix
public class Solution { public List spiralOrder(int[][] matrix) { List result = new ArrayList(); if (matrix == null || matrix.length == 0 || matrix[0] == null) {
2015-08-17 14:46:26
236
原创 Leetcode#53||Maximum Subarray
public class Solution { public int maxSubArray(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int length = nums.length;
2015-08-17 10:21:32
228
原创 Leetcode#50||Pow (x, n)
public class Solution { public double myPow(double x, int n) { if (n < 0) { return 1 / pow(x, -n); } else { return pow(x, n); } }
2015-08-17 10:13:52
281
原创 Leetcode#49||Group Anagrams
public class Solution { public List> groupAnagrams(String[] strs) { List> result = new ArrayList>(); if (strs == null || strs.length == 0) { return result;
2015-08-17 10:04:32
217
原创 Leetcode#48||Rotate Image
public class Solution { public void rotate(int[][] matrix) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return; } int length
2015-08-17 09:49:09
227
原创 Leetcode#45||Jump Game II
public class Solution { public int jump(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int left = 0; int right = 0;
2015-08-15 17:37:21
254
原创 Leetcode#43||Multiply Strings
public class Solution { public String multiply(String num1, String num2) { String s1 = new StringBuilder(num1).reverse().toString(); String s2 = new StringBuilder(num2).reverse().t
2015-08-15 17:02:31
266
原创 Leetcode#42||Trapping Rain Water
public class Solution { public int trap(int[] height) { if (height == null || height.length < 3) { return 0; } int result = 0; int maxHeightInd
2015-08-15 09:09:25
230
原创 Leetcode#41||First Missing Positive
public class Solution { public int firstMissingPositive(int[] nums) { if (nums == null || nums.length == 0) { return 1; } int length = nums.length;
2015-08-15 08:57:14
248
原创 Leetocde#38||Count and Say
public class Solution { public String countAndSay(int n) { if (n < 1) { return null; } String result = "1"; int t = n; while (
2015-08-15 08:17:34
218
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人