LeetCode
文章平均质量分 72
Problems and solutions on LeetCode
Xiao Cao
I prefer thinking and imaging than doing. I am looking for principles and truth.
展开
-
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).原创 2015-10-11 04:50:01 · 456 阅读 · 4 评论 -
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原创 2015-11-01 18:19:55 · 361 阅读 · 0 评论 -
Longest Common Prefix
题目 Write a function to find the longest common prefix string amongst an array of strings. 解题思路 首先选出一个字符串作为标准,然后注意细节。 代码 public class Solution{ public String longestCommonPrefix(String[] strs){原创 2015-11-01 19:04:03 · 360 阅读 · 0 评论 -
8. 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原创 2015-09-22 01:13:28 · 295 阅读 · 0 评论 -
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 Tho原创 2015-10-10 20:37:40 · 491 阅读 · 0 评论 -
9.Palindrome Number
题目 Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of c原创 2015-09-20 20:43:38 · 316 阅读 · 0 评论 -
Integer to Roman
题目 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 解题思路 从低位到高位分解数的每一位,然后用罗马字符串表示该位上的数,需要注意的是每次都从串头插入。 因为输入数据的取值范围很小,所以可以把每位原创 2015-10-09 15:27:09 · 263 阅读 · 0 评论 -
Roman to Integer
题目 Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 解题思路 组成罗马数字的字符一共有7个,均是大写的。I=1,V=5,X=10,L=50,C=100,D=500,M=1000 出现一次加一次原创 2015-10-09 14:48:32 · 234 阅读 · 0 评论 -
6.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 N A原创 2015-09-20 16:37:38 · 240 阅读 · 0 评论 -
4. 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)). 解题思路 这道题应该有更简洁的方法,我的原创 2015-09-20 14:14:02 · 366 阅读 · 0 评论 -
5.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. 解题思路 1.使用原创 2015-09-16 13:13:11 · 387 阅读 · 0 评论 -
3.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原创 2015-08-17 02:52:15 · 655 阅读 · 0 评论 -
7.Reverse Integer
题目 Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to ask原创 2015-09-15 23:11:51 · 439 阅读 · 0 评论 -
1.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 targe原创 2015-08-16 01:04:28 · 946 阅读 · 0 评论 -
2.Add Two Numbers
题目 You 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 numbers and return it a原创 2015-08-16 23:54:15 · 617 阅读 · 0 评论