leetcode 49 Group Anagrams

2018-07-14
阅读 1 分钟
1.5k
Given an array of strings, group anagrams together.题目要求输入一个字符串数组,我们要将由同样字母组成的字符串整理到一起,然后以如下例子中的格式输出。不需要关注输出的顺序,所有的输入都是小写。Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat","tan"], ["b...

leetcode 47 Permutations II

2018-05-04
阅读 2 分钟
2.8k
Given a collection of numbers that might contain duplicates, return all possible unique permutations.题目要求输入一个可能会有重复数字的数组nums,要求我们输出nums可能组成的全排列(无重复排列)。

leetcode 46 Permutations

2018-03-29
阅读 1 分钟
2.6k
Given a collection of distinct numbers, return all possible permutations. 题目要求我们对于输入的数字序列,给出它们的全排列。 例如,[1,2,3] 有如下的全排列:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]

leetcode 416 Partition Equal Subset Sum

2018-03-26
阅读 1 分钟
3.9k
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal. 题目的意思是输入一个非空的、只含正整数的数组nums,要求我们判断,数组nums能否被分成两个子数组,满足两个子数组的和相等。 例1:输入:...

leetcode 198 House Robber

2018-03-25
阅读 1 分钟
2.2k
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent hou...

leetcode 43 Multiply Strings

2018-03-23
阅读 2 分钟
3.5k
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:-The length of both num1 and num2 is < 110.-Both num1 and num2 contains only digits 0-9.-Both num1 and num2 does not contain any leading zero.-You must not use any built-in BigInteger...

leetcode 36 Valid Sudoku

2018-03-18
阅读 3 分钟
2.6k
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 '.'.输入一个二维数组表示的数独版(board)。要求我们判断已经填入的数字是否满足数独的规则。即满足每一行、每一列、每一个粗线宫(3*3)内的...

leetcode 29 Divide Two Integers

2018-03-17
阅读 2 分钟
3k
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. 题目要求我们在不借助乘法运算、除法运算和模运算的基础上,求出输入的两个整数相除的结果。如果溢出,那么返回MAX_INT。其中第一个参数是被除数,第二个参数是除数。

leetcode 24 Swap Nodes in Pairs

2018-03-14
阅读 1 分钟
2.3k
Given a linked list, swap every two adjacent nodes and return its head.题目要求输入一个链表,我们将相邻的两个节点的顺序翻转。最后返回头节点。同时题目要求只能占用常数空间,并且不能改变节点的值,改变的是节点本身的位置。 例如,输入 1->2->3->4, 你应该返回的链表:2->1->4->3.

leetcode 22 Generate Parentheses

2018-03-13
阅读 1 分钟
2.3k
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.输入一个正整数n。要求返回一个List<String>,list中包含n组括号所有可能的符合规则的组合。如“(())”就属于符合规则的组合,“)(()”就属于不符合规则的组合。 例如, 输入 n = 3, 结果集应当是:[ "((()...

leetcode 19 Remove Nth Node From End of List

2018-03-12
阅读 1 分钟
1.9k
Given a linked list, remove the nth node from the end of list and return its head.题目要求输入一个linked list 和一个数字n。要求我们返回删掉了倒数第n个节点的链表。 For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list becom...

leetcode 17 Letter Combinations of a Phone Number

2018-03-09
阅读 2 分钟
2.3k
Given a digit string, return all possible letter combinations that the number could represent. mapping of digit to letters (just like on the telephone buttons) is given below.这道题要求我们给出,对于输入的按键组合,我们需要返回按键所对应的所有可能的字符串。而按键和字母的对应关系如上图。

leetcode 12 Integer to Roman

2018-03-08
阅读 1 分钟
2.3k
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.题目的意思是: 输入一个阿拉伯数字,我们需要输出这个数字的罗马数字表示形式(字符串)。

leetcode 6 ZigZag Conversion

2018-03-04
阅读 2 分钟
1.9k
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)*P A H N*A P L S I I G*Y I RAnd then read line by line: "PAHNAPLSIIGYIR"Write the code that will take a string and make this ...

leetcode 5 Longest Palindromic Substring Java & JavaScript解法

2018-03-01
阅读 2 分钟
2.2k
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.题目的意思是输入一个字符串,我们要找到这个字符串的最长的满足回文条件的子字符串。回文的意思就是反转字符串后和原字符串相等。 Example:Input: "babad"Output: "bab"Note: "aba" is also a va...

leetcode 部分解答索引(持续更新~)

2018-02-28
阅读 2 分钟
2.8k
从开始写leetcode相关的博客到现在也蛮多篇了。而且当时也没有按顺序写~现在翻起来觉得蛮乱的。可能大家看着也非常不方便。所以在这里做个索引嘻嘻。

leetcode 1 Two Sum Java & JavaScript解法

2018-02-28
阅读 2 分钟
2.4k
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same element twice.题目的意思是,输入一个整数数组和一个目标和,让我们找整数数组中的两个元素,使他们的加...

leetcode 3 Longest Substring Without Repeating Characters

2018-02-23
阅读 1 分钟
2k
Given a string, find the length of the longest substring without repeating characters.题目要求输入一个字符串,我们要找出其中不含重复字符的最长子字符串,返回这个最长子字符串的长度。 Examples:输入"abcabcbb",最长不含重复字符子字符串"abc",返回3.输入"bbbbb",最长不含重复字符子字符串"b",返回1.输入"pwwke...

leetcode 2 Add Two Numbers

2018-02-23
阅读 2 分钟
1.8k
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.You may assume the two numbers do not contain any leading zero, except the num...

leetcode 48 Rotate Image

2018-02-22
阅读 2 分钟
2.6k
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. 这道题目要求我们对一个正方形矩阵进行顺...

leetcode 40 Combination Sum II

2018-02-21
阅读 2 分钟
1.9k
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination. 这道题的意思是,输入一个候选数字集(C)和一个目标数字(T).要求我们找出C中的不同元素组合,使得这些元...

leecode 39 Combination Sum

2018-02-19
阅读 2 分钟
1.5k
Given a set of candidate numbers (C) (without duplicates) 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 of times. 输入一个不含重复数字的候选的数字集(C)和一个目标数字(T)。我们需要找...

leetcode 28 Implement strStr()

2018-02-17
阅读 1 分钟
2.5k
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 题目要求我们实现strStr方法。就是在一个长字符串中是否包含我们所输入的子字符串。如果存在,返回子字符串的在长字符串的起始点的位置。如果不存在,则返回-1。 Example 1:Input: hays...

leetcode 34 Search for a Range

2018-02-16
阅读 2 分钟
1.8k
Given an array of integers sorted in ascending order, 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 the array, return [-1, -1].题目的意思是,输入一个升序排列的整数数组和一个目标值。...

leetcode 33 Search in Rotated Sorted Array

2018-02-15
阅读 1 分钟
1.8k
Suppose an array sorted in ascending order 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 its index, otherwise return -1.题目的输入是一个被旋转过的升序排列数组。(如正常的升序...

leetcode 31 Next Permutation

2018-02-14
阅读 2 分钟
3k
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 order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory...

leetcode 20 Valid Parentheses

2018-02-13
阅读 1 分钟
2.3k
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 but "(]" and "([)]" are not.输入一个字符串s,这个字符串是由字符'(', ')', '{', '}', '[' 和 ']'组成的。...

leetcode 18 4Sum

2018-02-13
阅读 2 分钟
2k
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.输入一个长度为n的整数数组和一个目标整数target,我们需要找出是否存在4个元素a、b、c、d,使得abcd的和等于target。如果有,输...

leetcode 14 Longest Common Prefix

2018-02-12
阅读 1 分钟
1.7k
Write a function to find the longest common prefix string amongst an array of strings. 题目要求是,给定一个字符串的数组,我们要找到所有字符串所共有的最长的前缀。

leetcode 16 3Sum Closest

2018-02-12
阅读 1 分钟
1.9k
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.给定一个整数数组,我们需要找出数组中三个元素的加和,使这个加和最接近于输入的target...