摘要:
LeetCode - 3Sum2013.12.1 23:52Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) must be in non-descending order. (ie,a≤b≤c)The solution set must not contain duplicate triplets. 阅读全文
摘要:
LeetCode - Longest Common Prefix2013.12.1 23:23Write a function to find the longest common prefix string amongst an array of strings.Solution: For two string s1 and s2, compare the elements from the beginning, when the end or the first mismatch is found, the common prefix is found. For n strings s.. 阅读全文
摘要:
LeetCode - Roman to Integer2013.12.1 23:16Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Solution: Given a Roman number, convert it to normal arabian form. Just do the conversion from left to right, one digit by one. Here is the wiki if yo.. 阅读全文
摘要:
LeetCode - Integer to Roman2013.12.1 22:56Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.Solution: First of all, for those who lacks background knowledge of Roman numerals(including me), here is the wiki: http://en.wikipedia.org/wiki/Rom... 阅读全文
摘要:
LeetCode - Palindrome Number2013.12.1 22:24Determine 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 converting the integer to string, note the restriction of using extra space.Yo 阅读全文
摘要:
LeetCode - Reverse Integer2013.12.1 22:12Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!If the i 阅读全文
摘要:
LeetCode - ZigZag Conversion2013.12.1 21:48The 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 I GY I RAnd then read line by line:"PAHNAPLSIIGYIR" 阅读全文
摘要:
LeetCode - Add Two Numbers2013.12.1 21:03You 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 as a linked list.Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)Outp 阅读全文
摘要:
LeetCode - Longest Substring Without Repeating Characters2013.12.1 19:50Given 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. For "bb 阅读全文
摘要:
Median of Two Sorted Arrays2013.12.1 19:29There 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)).Solution: Given two sorted array, find out the median of all elements. My solution is straight. 阅读全文