摘要: Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to... 阅读全文
posted @ 2014-11-26 10:47 vincently 阅读(244) 评论(0) 推荐(0) 编辑
摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value t... 阅读全文
posted @ 2014-11-26 10:03 vincently 阅读(513) 评论(0) 推荐(0) 编辑
摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal... 阅读全文
posted @ 2014-11-25 14:46 vincently 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Write a function to find the longest common prefix string amongst an array of strings.思路:每个字符串都与第0个字符串比较,设置一个变量,记录每个字符串与第0个字符串不匹配位置的最小值 时间复杂度O(n1+n2... 阅读全文
posted @ 2014-11-24 15:41 vincently 阅读(129) 评论(0) 推荐(0) 编辑
摘要: Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100"思路:时间复杂度O(n), 空间复杂度O(1) 1 class Solution { 2 pub... 阅读全文
posted @ 2014-11-04 22:06 vincently 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 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 @ 2014-11-04 16:53 vincently 阅读(230) 评论(0) 推荐(0) 编辑
摘要: Given a string, determine if it is a palindrome, considering only alphanumericcharacters and ignoring cases.For example,"A man, a plan, a canal: Panam... 阅读全文
posted @ 2014-11-04 14:53 vincently 阅读(151) 评论(0) 推荐(0) 编辑
摘要: Given a singlylinked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For examp... 阅读全文
posted @ 2014-11-04 13:17 vincently 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?思路:... 阅读全文
posted @ 2014-11-04 09:57 vincently 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:快慢指针的应用。快慢指针指的是移动的步长,即每次向前移动的快慢。例如可以让快指... 阅读全文
posted @ 2014-11-03 20:29 vincently 阅读(145) 评论(0) 推荐(0) 编辑