随笔分类 -  leetcode

Min Stack
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. to... 阅读全文

posted @ 2014-11-15 22:26 openqt 阅读(244) 评论(0) 推荐(0)

Find Minimum in Rotated Sorted Array II
摘要:Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose a sorted array is rotated at some pivot unknown ... 阅读全文

posted @ 2014-10-21 16:51 openqt 阅读(269) 评论(1) 推荐(0)

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

posted @ 2014-10-21 01:16 openqt 阅读(153) 评论(0) 推荐(0)

3Sum Closest
摘要: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 exactl... 阅读全文

posted @ 2014-10-21 00:29 openqt 阅读(219) 评论(0) 推荐(0)

4Sum
摘要: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. Note: Elements in a... 阅读全文

posted @ 2014-10-20 23:32 openqt 阅读(209) 评论(0) 推荐(0)

3Sum
摘要:Given an array S of n integers, are there elements a, b, c in S such that a + 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... 阅读全文

posted @ 2014-10-20 21:09 openqt 阅读(254) 评论(0) 推荐(0)

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

posted @ 2014-10-18 23:28 openqt 阅读(257) 评论(0) 推荐(0)

Longest Common Prefix
摘要:Write a function to find the longest common prefix string amongst an array of strings. 分析: 对一组字符串找到最长公共前缀。 因为只是找前缀所以可以以第一个字符串为基础,按个字符与其它字符串比较,直到有字符串已经遍历完或者碰到不一致的字符,返回到当前为止第一个字符串的前缀即可。 class Solution... 阅读全文

posted @ 2014-10-18 21:16 openqt 阅读(185) 评论(0) 推荐(0)

Find Minimum 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). Find the minimum element. You may assume no duplicate exists in the arr... 阅读全文

posted @ 2014-10-18 19:52 openqt 阅读(257) 评论(0) 推荐(0)

导航