- 博客(51)
- 资源 (1)
- 问答 (3)
- 收藏
- 关注
原创 LeetCode Remove Duplicates from Sorted List & Remove Duplicates from Sorted List II
Description: Solution:
2015-06-30 22:55:44 283
原创 LeetCode Remove Duplicates from Sorted Array II
Description: Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? Solution:
2015-06-30 22:55:06 256
原创 LeetCode Word Search
Description: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizont
2015-06-30 21:36:17 312
原创 LeetCode Subsets
Description: Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order.The solution set must not contain duplicate su
2015-06-30 20:59:04 204
原创 LeetCode Combinations
Description: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. Solution: 排列组合,也是前面已经用到过的方法,用DFS来解决。 import java.util.*; public class Solution { List
2015-06-30 20:44:20 278
原创 LeetCode Sort Colors
Description: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will
2015-06-30 20:27:21 237
原创 LeetCode Search a 2D Matrix
Description: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right.The fir
2015-06-30 00:56:00 278
原创 LeetCode Set Matrix Zeroes
Description: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space? A straight forward solution using O(mn) space
2015-06-30 00:28:12 429
原创 LeetCode Simplify Path
Description: Given an absolute path for a file (Unix-style), simplify it. Solution: 用scanner和stack处理即可,用"/"作为分割器,然后每次遇到".."就出栈。最后将stack倒序输出即可。 import java.util.*; public class Solution { publi
2015-06-30 00:25:48 275
原创 LeetCode Climbing Stairs
Description: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Solution: d
2015-06-29 21:56:33 309
原创 LeetCode Sqrt(x)
Description: Compute and return the square root of x. Solution: 二分咯,但是对于l import java.util.*; public class Solution { public int mySqrt(int x) { if (x == 0 || x == 1) return x; long l =
2015-06-29 21:42:45 249
原创 LeetCode Add Binary
Description: Given two binary strings, return their sum (also a binary string). Solution: 将十进制的加法变成二进制的加法,做了三四道类似的,大家应该很熟悉了。 import java.util.*; public class Solution { public String addBinary
2015-06-29 19:25:24 380
原创 LeetCode Plus One
Description: Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. Solu
2015-06-29 19:19:40 291
原创 LeetCode Minimum Path Sum
Description: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Solution: 经典的DP题目 还有一种出法是给一
2015-06-29 00:21:04 276
原创 LeetCode Unique Paths II
Description: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 resp
2015-06-28 23:42:20 268
原创 LeetCode Unique Paths
Description: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is tr
2015-06-28 23:38:12 270
原创 LeetCode Rotate
Description: Given a list, rotate the list to the right by k places, where k is non-negative. Solution: 这道题目还是经典的链表操作题。 首先先让一个标记b走k次。 然后让a和b同时开始走,一直到b走到了链表尾,此时a所在的位置就是进行分割的地方。 注意:这里k有可能比链表的长
2015-06-28 23:16:11 319
原创 LeetCode Permutation Sequence
Description: he set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): "123"
2015-06-28 20:59:12 260
原创 LeetCode Rotate Image
Description: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Solution: Get the transformation matrix: mat[i][j] -> mat[j][n-1-i] import j
2015-06-28 20:10:33 251
原创 LeetCode Spiral Matrix II
Description: Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order Solution: 这道题目和Spiral Matrix机会没什么区别,把过程反过来即可。 还是注意一个问题,就是当n是奇数的时候,会有旋转“不完整”的一个点,最中
2015-06-28 17:11:54 271
原创 LeetCode Length of Last Word
Description: Length of Last Word Solution: A scanner class can read the String and divide them with the default dlimiter of ' '. import java.util.*; public class Solution { public int lengthO
2015-06-28 14:00:13 283
原创 LeetCode Jump Game
Description: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that positi
2015-06-28 12:19:20 237
原创 LeetCode Maximum Subarray
Description: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous suba
2015-06-28 01:45:39 254
原创 LeetCode Pow(x, n)
Description: Implement pow(x, n). Solution: public class Solution { public double myPow(double x, int n) { double ans = 1.0; if (n == 0) return 1; boolean converse = false; i
2015-06-28 01:33:16 253
原创 LeetCode Permutations
Description: Given a collection of numbers, return all possible permutations. Solution: I remember this is the most basic algorithm on the book Data Structure. import java.util.ArrayList; import
2015-06-27 17:38:30 220
原创 LeetCode Multiply Strings
Description: Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. Solution: We can div
2015-06-27 17:28:35 271
原创 LeetCode Combination Sum & Combination Sum II
Combination Sum Description: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated num
2015-06-27 10:19:56 454
原创 LeetCode Count and Say
Description: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21.
2015-06-25 21:00:10 231
原创 LeetCode Valid Sudoku
Description: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. Solutio
2015-06-25 19:51:42 211
原创 LeetCode Search Insert Position
Description: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Solution: This problem is
2015-06-25 19:37:00 184
原创 LeetCode Search for a Range
Description: Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the ta
2015-06-25 17:15:08 205
原创 LeetCode Next Permutation
Description: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as t
2015-06-25 09:52:02 312
原创 LeetCode Divide Two Integers
Description: Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. Solution: 感觉用英文说不清了……哎…… 是这样的,既然不能用乘除法,老夫的第一个反应是将被除数依次二分,dfs一下,这
2015-06-24 21:44:59 270
原创 LeetCode Implement strStr()
Description: Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Solution: Only one needle need to be checked. Or else we need to use an Aho-
2015-06-24 15:37:45 248
原创 LeetCode Remove Element
Description: Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond th
2015-06-24 15:29:38 202
原创 LeetCode Remove Duplicates from Sorted Array
Description: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do
2015-06-24 15:27:34 268
原创 LeetCode Swap Nodes in Pairs
Description: Given a linked list, swap every two adjacent nodes and return its head. Solution: We can get two list nodes each time, then just simply switch them. Remember that there are three 'ne
2015-06-24 14:55:32 287
原创 LeetCode Generate Parentheses
Description: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Solution: A dfs can solve this problem, We can imagine this problem as settin
2015-06-24 14:21:02 297
原创 LeetCode 4Sum
Description: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.
2015-06-21 18:12:51 270
java中的sql语句为何会报错,而到了workbench就可以执行
2015-03-17
Python获得网卡IP的几个参数问题
2015-01-12
Python中注释前面加上引号是什么意思?
2014-12-30
TA创建的收藏夹 TA关注的收藏夹
TA关注的人