leetcode
文章平均质量分 82
iteye_6755
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit strin...2015-05-28 19:22:10 · 90 阅读 · 0 评论 -
4Sum
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.Note:Elements in ...2015-05-28 19:33:58 · 96 阅读 · 0 评论 -
Pow(x, n)
Implement pow(x, n). public class Solution { public double myPow(double x, int n) { if (n < 0) { return 1.0 / power(x, -n); } else if (n > 0) { r...2015-05-28 22:14:17 · 86 阅读 · 0 评论 -
Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node fro...2015-06-01 13:01:33 · 76 阅读 · 0 评论 -
Valid Parentheses
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 valid b...2015-06-01 13:17:41 · 78 阅读 · 0 评论 -
Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. public class Solution { public ListNode mergeTwo...2015-06-02 13:27:17 · 78 阅读 · 0 评论 -
Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()...2015-06-02 13:36:58 · 86 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. /** * Definition for singly-linked list. * public class ListNode { * int val; * ...2015-06-03 22:08:04 · 81 阅读 · 0 评论 -
Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only con...2015-06-03 22:55:21 · 89 阅读 · 0 评论 -
Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is...2015-06-04 22:37:03 · 88 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
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 this in place with ...2015-06-04 22:56:40 · 73 阅读 · 0 评论 -
Remove Element
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 the new length. ...2015-06-05 15:20:28 · 81 阅读 · 0 评论 -
Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. public class Solution { public int strStr(String haystack, Str...2015-06-05 16:38:45 · 81 阅读 · 0 评论 -
Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. public class Solution { public int divide(int dividend, int divisor) { ...2015-06-05 19:08:29 · 76 阅读 · 0 评论 -
Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in wordsexactly once and wi...2015-06-06 23:07:15 · 115 阅读 · 0 评论 -
Next Permutation
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 the lowest possible...2015-06-07 10:45:43 · 89 阅读 · 0 评论 -
Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", whic...2015-06-07 11:14:00 · 88 阅读 · 0 评论 -
Search in Rotated Sorted Array
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 return it...2015-06-07 11:48:15 · 79 阅读 · 0 评论 -
Search for a Range
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 in...2015-06-07 12:35:57 · 80 阅读 · 0 评论 -
Search Insert Position
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.You may assume no duplicates in the array....2015-06-08 21:47:20 · 80 阅读 · 0 评论 -
Valid Sudoku
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 '.'.A partially filled sudok...2015-06-08 22:16:22 · 74 阅读 · 0 评论 -
Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku puzzle.....2015-06-08 22:33:26 · 88 阅读 · 0 评论 -
Count and Say
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.21 is read off as "one 2, the...2015-06-10 13:43:15 · 88 阅读 · 0 评论 -
Combination Sum
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 number may be chosen from C unlimited number...2015-06-10 18:37:47 · 98 阅读 · 0 评论 -
Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums toT.Each number in C may only be used once in the combinatio...2015-06-11 09:30:04 · 96 阅读 · 0 评论 -
First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant space...2015-06-11 10:50:37 · 80 阅读 · 0 评论 -
Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], ...2015-06-11 14:03:50 · 84 阅读 · 0 评论 -
Multiply Strings
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. public class Solution { public S...2015-06-11 19:48:33 · 87 阅读 · 0 评论 -
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 cov...2015-06-12 11:55:59 · 90 阅读 · 0 评论 -
Jump Game II
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 position.Your goal is ...2015-06-12 13:38:05 · 83 阅读 · 0 评论 -
Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. public class Solut...2015-06-14 10:23:38 · 113 阅读 · 0 评论 -
Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list. /** * Definition for singly...2015-06-14 11:14:18 · 86 阅读 · 0 评论 -
Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() --...2015-06-15 18:47:09 · 84 阅读 · 0 评论 -
Single Number II
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 using ...2015-06-16 21:59:12 · 89 阅读 · 0 评论 -
Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return[ ["aa","b"],...2015-06-16 23:09:40 · 87 阅读 · 0 评论 -
Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1]. p...2015-06-18 22:23:26 · 91 阅读 · 0 评论 -
Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place? public class Solution { public void rotate(int[][]...2015-06-18 23:02:45 · 88 阅读 · 0 评论 -
Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case. public class Solution { public List<String> anagrams(String[] strs) ...2015-06-19 12:30:37 · 140 阅读 · 0 评论 -
N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Ea...2015-06-19 13:57:01 · 102 阅读 · 0 评论 -
N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. public class Solution { private int num = 0; public int totalNQ...2015-06-19 14:01:31 · 101 阅读 · 0 评论
分享