自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(91)
  • 资源 (1)
  • 收藏
  • 关注

转载 Search in Rotated Sorted Array II - LeetCode

Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the

2014-03-08 13:55:52 644

原创 Unique Paths - LeetCode

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 trying to reach the

2014-03-08 12:54:06 622

原创 Sum Root to Leaf Numbers - LeetCode

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota

2014-03-08 12:35:35 618

转载 Edit Distance - LeetCode

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:

2014-03-08 12:04:19 767

原创 Restore IP Addresses - LeetCode

Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order

2014-03-08 11:37:06 667

转载 N-Queens II - LeetCode

Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.本题主要是深度优先搜索:public class Solution { public int totalNQueens

2014-03-08 03:08:59 660

转载 String to Integer (atoi) - LeetCode

Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca

2014-03-08 01:14:03 902

原创 Valid Palindrome - LeetCode

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a

2014-03-08 00:25:03 659

转载 Word Ladder - LeetCode

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediat

2014-03-07 16:11:54 1134

转载 Surrounded Regions - LeetCode

Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O X

2014-03-07 15:01:04 639

转载 Validate Binary Search Tree - LeetCode

Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th

2014-03-07 14:48:52 539

原创 Decode Ways - LeetCode

开始写了一个标准的DP,但是由于对于题意中的0没有弄清楚,所以没过:public class Solution {public int numDecodings(String s) { if(s == null) return 0; else if(s.length() == 0) return 0; int[] method = new int[s.le

2014-03-07 14:33:17 650

原创 Word Search - leetcode

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 horizontally or vertically

2014-03-07 13:46:19 627

原创 Set Matrix Zeroes - LeetCode

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.AC代码,虽然有点复杂,但是一次通过了。public class Solution { public void setZeroes(int[][] matrix) {

2014-03-07 12:34:47 579

转载 Anagrams - LeetCode

Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.这是我找到的最喜欢的解法。/* The idea is to use a hashmap to collect groups of anagr

2014-03-07 12:20:00 624

原创 Multiply Strings - LeetCode

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.首先,展示一个我看到的最吊,碉堡了的算法:import java.math

2014-03-07 11:59:42 579

原创 Search for a Range - LeetCode

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 target is not found

2014-03-07 11:23:22 450

原创 Divide Two Integers - LeetCode

最初想到的简单暴力算法,超时了:public class Solution { public int divideHelper(int dividend, int divisor){ int result = 0; if(divisor == 0) return 0; else{ while(true){

2014-03-07 09:40:34 586

原创 Implement strStr() - LeetCode

Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.这道题有很多需要注意的小点:(1)You have to check if a String == null before

2014-03-07 09:09:59 556

原创 Valid Parentheses - LeetCode

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va

2014-03-07 08:42:18 549

原创 Container With Most Water - LeetCode

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin

2014-03-03 13:01:32 633

转载 Regular Expression Matching - LeetCode

利用递归的算法,观察*的位置,这道题非常好。public class Solution { public boolean isMatch(String s, String p) { // Start typing your Java solution below // DO NOT write main() function if(s.l

2014-03-03 12:13:37 529

转载 Longest Palindromic Substring - LeetCode

转自: http://blog.csdn.net/pickless/article/details/9040293选定一个位置,朝两边不断拓展,直到两边的字符不一样为止。这是最简单、最直观的想法,这个想法的时间复杂度是O(n2)。但是这不是最快速的算法,目前对于最长回文子串问题最快的解法的时间复杂度为O(n)。假设S=“gxgag

2014-03-03 10:48:04 410

转载 leetcode难度及面试频率

1Two Sum25arraysort    setTwo Pointers2Add Two Numbers34linked listTwo Pointers   

2014-03-03 09:03:22 642

原创 Median of Two Sorted Arrays - LeetCode

There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).我写的太不简洁了,也没有优化,不过AC了:public cla

2014-03-03 08:49:12 571

转载 Gray Code

http://blog.csdn.net/sbitswc/article/details/20110655

2014-03-03 08:04:06 555

原创 Merge Sorted Array - LeetCode

Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from

2014-02-26 05:40:23 660

原创 Maximum Subarray - LeetCode

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 subarray [4,−1,2,1] ha

2014-02-26 05:07:19 657

原创 Single Number II - LeetCode

Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi

2014-02-26 04:50:28 595

转载 Populating Next Right Pointers in Each Node - LeetCode

http://blog.csdn.net/pickless/article/details/12027997

2014-02-26 04:08:22 592

原创 Binary Tree Preorder Traversal - LeetCode

Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti

2014-02-26 03:24:59 576

原创 Unique Binary Search Trees - LeetCode

Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \

2014-02-26 00:47:42 566

原创 Same Tree - LeetCode

Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Defin

2014-02-25 23:43:21 550

转载 Remove Duplicates from Sorted Array II - LeetCode

Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,

2014-02-25 15:37:09 587

转载 Longest Substring Without Repeating Characters - LeetCode

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo

2014-02-25 15:34:05 515

转载 Reorder List - LeetCode

Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to

2014-02-25 15:07:30 670

转载 Construct Binary Tree from Preorder and Inorder Traversal - LeetCode

Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.推荐链接:推荐链接public class Solution { private

2014-02-25 13:11:24 678

转载 Construct Binary Tree from Inorder and Postorder Traversal - LeetCode

Given inorder and postorder traversal of a tree, construct the binary tree./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right;

2014-02-25 12:32:40 864

转载 Convert Sorted Array to Binary Search Tree - LeetCode

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.public class Solution { private TreeNode buildTree(int[] num, int start, int end) { if (s

2014-02-25 12:04:22 484

转载 Search in Rotated Sorted Array - LeetCode

Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur

2014-02-25 11:26:04 596

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除