leetcode
文章平均质量分 58
sanfendi
这个作者很懒,什么都没留下…
展开
-
LeetCode——Implement strStr()
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.原题链接:https://oj.leetcode.com/problems/implement-strstr/题目:实现strStr原创 2014-07-16 09:34:50 · 1701 阅读 · 0 评论 -
LeetCode——Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2014-06-23 20:07:08 · 1432 阅读 · 0 评论 -
LeetCode——Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-原创 2014-07-15 20:20:35 · 1728 阅读 · 0 评论 -
LeetCode——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 u原创 2014-06-24 13:32:18 · 1519 阅读 · 0 评论 -
LeetCode——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 va原创 2014-07-17 09:33:27 · 1835 阅读 · 0 评论 -
LeetCode——Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2014-06-07 20:37:35 · 1551 阅读 · 0 评论 -
LeetCode——Sum Root to Leaf Numbers
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-06-26 19:23:41 · 1535 阅读 · 0 评论 -
LeetCode——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:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-07-18 08:21:31 · 2225 阅读 · 0 评论 -
LeetCode——Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2014-06-27 09:48:03 · 1548 阅读 · 0 评论 -
LeetCode——Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.给定一个整数,把它转换成罗马数字。输入可以保证在1到3999之间。下图是转换规则。1234原创 2014-06-28 19:51:37 · 1400 阅读 · 0 评论 -
LeetCode——Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.给定一个罗马数字,把它转换成一个整数。把罗马数字字符串转换成字符数组先,如下表,每个数字仅对应一个字符,而且字符不一样。故可从头开始取值进行对应。The R原创 2014-06-28 20:12:57 · 1419 阅读 · 0 评论 -
LeetCode——Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2014-06-10 10:19:22 · 1534 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
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-06-10 11:52:38 · 1319 阅读 · 0 评论 -
LeetCode——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".Clarification:What constitutes a word?A sequence of non-space ch原创 2014-06-10 09:59:21 · 1506 阅读 · 0 评论 -
LeetCode——Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2014-07-19 10:20:30 · 2182 阅读 · 0 评论 -
LeetCode——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原创 2014-06-30 09:42:41 · 1343 阅读 · 0 评论 -
LeetCode——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.中原创 2014-06-10 10:42:31 · 1613 阅读 · 0 评论 -
LeetCode——Plus One
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.原创 2014-06-10 13:56:47 · 1285 阅读 · 0 评论 -
LeetCode——Add Two Numbers
Add Two NumbersYou are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two原创 2014-06-08 20:47:00 · 1692 阅读 · 0 评论 -
LeetCode——Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.中文:原创 2014-06-10 14:54:01 · 1196 阅读 · 0 评论 -
LeetCode——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 from the end, the原创 2014-07-20 13:10:24 · 1725 阅读 · 0 评论 -
LeetCode——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 st原创 2014-07-21 16:14:35 · 1902 阅读 · 0 评论 -
LeetCode——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.原创 2014-07-01 10:24:32 · 1357 阅读 · 0 评论 -
LeetCode——Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2014-06-11 18:47:27 · 1564 阅读 · 0 评论 -
LeetCode——Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.中文:给一二叉树,找出其最小深度。最小深度是从根节点到最近的原创 2014-06-11 19:15:56 · 1408 阅读 · 0 评论 -
LeetCode——Same Tree
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.中文:给定两二叉树,原创 2014-06-11 09:21:32 · 1490 阅读 · 0 评论 -
LeetCode——Longest Substring Without Repeating Characters
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-07-02 12:17:48 · 1414 阅读 · 0 评论 -
LeetCode——Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2014-06-12 17:49:27 · 1554 阅读 · 0 评论 -
LeetCode——Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2014-06-12 17:06:31 · 1427 阅读 · 0 评论 -
LeetCode——Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.此题和求二叉树的最短路径几乎一模一样。 public int原创 2014-06-12 17:14:15 · 1533 阅读 · 0 评论 -
LeetCode——Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string原创 2014-07-03 12:42:20 · 1346 阅读 · 0 评论 -
LeetCode——Median of Two Sorted Arrays
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)).有两个已排序的数组A和B,大小为m 和 n。找出两数组的中原创 2014-07-04 19:40:31 · 1574 阅读 · 0 评论 -
LeetCode——Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.给定一个字符串S,找出其中的最长回文原创 2014-07-05 09:37:55 · 1528 阅读 · 0 评论 -
LeetCode——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原创 2014-07-06 17:52:48 · 1780 阅读 · 0 评论 -
LeetCode——ZigZag Conversion
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 NA P L S I原创 2014-07-06 09:17:50 · 1334 阅读 · 0 评论 -
LeetCode——String to Integer (atoi)
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-07-06 14:35:22 · 1399 阅读 · 0 评论 -
LeetCode——Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.写一个函数找出字符串数组中的最长共现前缀字符串。思路:共现,即要求数组中的所有元素的前缀中都要出现。所以所得的结果肯定是最短字符串的部分或全部或都不是,总之要以最短字符串为基准与其他字符串比较。 public Str原创 2014-07-08 09:44:12 · 1756 阅读 · 0 评论 -
LeetCode——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 retur原创 2014-07-26 11:15:26 · 1710 阅读 · 0 评论 -
LeetCode——Container With Most Water
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-07-07 18:58:17 · 1615 阅读 · 0 评论 -
LeetCode——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 constant space. Y原创 2014-07-27 11:08:29 · 1936 阅读 · 0 评论