2013年10月17日

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 fo... 阅读全文

posted @ 2013-10-17 14:51 Step-BY-Step 阅读(230) 评论(0) 推荐(0) 编辑

String to Integer (atoi)

摘要: Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ... 阅读全文

posted @ 2013-10-17 14:22 Step-BY-Step 阅读(207) 评论(0) 推荐(0) 编辑

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 converting the integer to string, note the restriction of using extra space.You could also try reversing an integer. Howe 阅读全文

posted @ 2013-10-17 13:49 Step-BY-Step 阅读(138) 评论(0) 推荐(0) 编辑

Container With Most Water

摘要: Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.Note: You 阅读全文

posted @ 2013-10-17 12:31 Step-BY-Step 阅读(127) 评论(0) 推荐(0) 编辑

Longest Common Prefix

摘要: Write a function to find the longest common prefix string amongst an array of strings.一个个比就行了,找到最长的匹配子串。 1 public class Solution { 2 public String longestCommonPrefix(String[] strs) { 3 // Note: The Solution object is instantiated only once and is reused by each test case. 4 if(s... 阅读全文

posted @ 2013-10-17 12:27 Step-BY-Step 阅读(149) 评论(0) 推荐(0) 编辑

求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)

摘要: 转自 http://tech-wonderland.net/blog/summary-of-ksum-problems.html前言:做过leetcode的人都知道, 里面有2sum, 3sum(closest), 4sum等问题, 这些也是面试里面经典的问题, 考察是否能够合理利用排序这个性质, 一步一步得到高效的算法. 经过总结, 本人觉得这些问题都可以使用一个通用的K sum求和问题加以概括消化, 这里我们先直接给出K Sum的问题描述和算法(递归解法), 然后将这个一般性的方法套用到具体的K, 比如leetcode中的2Sum, 3Sum, 4Sum问题. 同时我们也给出另一种哈希算法 阅读全文

posted @ 2013-10-17 11:59 Step-BY-Step 阅读(510) 评论(0) 推荐(0) 编辑

4Sum

摘要: Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d)The solution set must not contain duplicate quadruplets. . 阅读全文

posted @ 2013-10-17 11:58 Step-BY-Step 阅读(164) 评论(0) 推荐(0) 编辑

3Sum Closest

摘要: Given an arraySofnintegers, find three integers inSsuch 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. For example, given array S = {-1 2 1 -4}, and target = 1. The sum that is closest to ... 阅读全文

posted @ 2013-10-17 11:47 Step-BY-Step 阅读(162) 评论(0) 推荐(0) 编辑

导航