- 博客(262)
- 收藏
- 关注
原创 数组:Remove Element&Merge Sorted Array&First Missing Positive
Remove Elementpublic int removeElement(int[] nums, int val) { int count = 0; for(int i=0;i<nums.length;i++){ if(nums[i]!=val){ nums[count] = nums[i];
2015-10-22 11:42:29
418
原创 遍历技巧:2,3,4sum&3sum closest&set matrix zeroes&Container With Most Water
2 sumpublic class Solution { public int[] twoSum(int[] nums, int target) { int[] res = new int[2]; HashMap map = new HashMap(); for(int i=0;i<nums.length;i++){
2015-10-21 09:31:36
426
转载 Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 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)).public class Solution {
2015-10-05 08:27:17
393
转载 Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on
2015-10-02 06:38:41
386
转载 Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st
2015-10-02 06:34:14
271
转载 Best Time to Buy and Sell Stock IV
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.public class Solu
2015-10-02 06:21:58
340
转载 Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN
2015-10-02 06:14:05
239
转载 Dungeon Game
https://leetcode.com/problems/dungeon-game/public class Solution { public int calculateMinimumHP(int[][] dungeon) { if (dungeon == null || dungeon.length == 0 || dungeon[0].length == 0) r
2015-10-02 06:03:04
283
转载 Expression Add Operators
Given a string that contains only digits 0-9 and a target value, return all possibilities to add binaryoperators (not unary) +, -, or * between the digits so they evaluate to the target value.
2015-10-02 05:57:47
291
转载 Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For exam
2015-10-02 05:48:01
249
转载 Wildcard matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t
2015-10-02 04:30:18
247
转载 word search II
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those hor
2015-09-30 23:49:28
310
原创 LRU cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if
2015-09-30 23:26:39
265
转载 Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i
2015-09-28 03:23:59
234
转载 Word Ladder II(BFS + DFS)
Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a timeEac
2015-09-28 02:55:17
315
转载 Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line./* * A line is determined by two factors,say y=ax+b * * If two points(x1,y1) (x2,
2015-09-27 23:44:03
324
原创 Valid Number
public class Solution { public boolean isNumber(String s) { s = s.trim(); boolean pointSeen = false; boolean eSeen = false; boolean numberSeen = false; boolean numberAfterE =
2015-09-27 21:25:30
323
转载 Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3
2015-09-27 11:38:48
240
转载 Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.
2015-09-27 11:14:09
267
转载 Surrounded Regions
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
2015-09-27 10:44:49
266
转载 Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution {public: int divide(int dividend, int divisor) { if (!
2015-09-27 03:45:02
213
转载 Integer to English Words
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,123 -> "One Hundred Twenty Three"12345 -> "Twelve Thousand Th
2015-09-27 03:23:39
239
转载 Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".public class Solution { public String reverseWords(String s) {
2015-09-27 02:38:32
202
转载 Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i an
2015-09-27 02:26:17
237
原创 Decode ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu
2015-09-26 23:04:16
230
转载 Basic Calculator
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em
2015-09-26 04:40:30
217
原创 Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should
2015-09-26 02:58:15
206
转载 Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest
2015-09-24 11:00:25
221
转载 Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did
2015-09-24 10:05:04
269
原创 Validate Binary Search Tree
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
2015-09-24 09:35:07
205
转载 Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0
2015-09-23 05:04:44
189
转载 Number of Digit One(数学找规律)
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the follow
2015-09-23 03:29:31
249
转载 Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first
2015-09-23 03:12:17
189
转载 Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2015-09-23 02:19:15
208
原创 Word Search
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
2015-09-23 01:34:01
206
转载 Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.public class Solution { public String multiply(String num1, String num2) { if (num1 == null ||
2015-09-22 10:43:40
196
转载 Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely fille
2015-09-22 10:20:25
191
转载 Restore IP Addresses(DFS的巅峰)
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
2015-09-22 10:07:04
214
转载 Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",
2015-09-22 02:54:53
209
转载 Peeking Iterator
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be
2015-09-21 22:20:42
326
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人