随笔分类 -  Leetcode

摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or... 阅读全文
posted @ 2015-07-24 10:38 amazingzoe 阅读(127) 评论(0) 推荐(0)
摘要:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord... 阅读全文
posted @ 2015-07-24 10:19 amazingzoe 阅读(103) 评论(0) 推荐(0)
摘要:Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh... 阅读全文
posted @ 2015-07-23 11:44 amazingzoe 阅读(158) 评论(0) 推荐(0)
摘要:Sort a linked list in O(n log n) time using constant space complexity.Analyse: When it comes to O(nlogn), we need to think of sort algorithms like mer... 阅读全文
posted @ 2015-07-23 10:09 amazingzoe 阅读(205) 评论(0) 推荐(0)
摘要:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.Analyse: Similiar to merge sort algorithm. Reuse the c... 阅读全文
posted @ 2015-07-21 22:00 amazingzoe 阅读(129) 评论(0) 推荐(0)
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great... 阅读全文
posted @ 2015-07-21 18:30 amazingzoe 阅读(136) 评论(0) 推荐(0)
摘要:Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest... 阅读全文
posted @ 2015-07-21 17:17 amazingzoe 阅读(130) 评论(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 @ 2015-06-23 14:55 amazingzoe 阅读(125) 评论(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 @ 2015-05-20 21:52 amazingzoe 阅读(139) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?分析:用map记录是否出现过。用时:60ms 1 /** 2 * Definiti... 阅读全文
posted @ 2015-05-20 21:38 amazingzoe 阅读(136) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor... 阅读全文
posted @ 2015-05-20 00:46 amazingzoe 阅读(214) 评论(0) 推荐(0)
摘要:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.分析:首先... 阅读全文
posted @ 2015-05-18 18:57 amazingzoe 阅读(194) 评论(0) 推荐(0)
摘要:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... 阅读全文
posted @ 2015-05-18 18:10 amazingzoe 阅读(130) 评论(0) 推荐(0)
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2015-05-18 15:33 amazingzoe 阅读(112) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime comp... 阅读全文
posted @ 2015-05-16 22:03 amazingzoe 阅读(108) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity... 阅读全文
posted @ 2015-05-16 21:42 amazingzoe 阅读(130) 评论(0) 推荐(0)
摘要:There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requi... 阅读全文
posted @ 2015-05-16 19:42 amazingzoe 阅读(180) 评论(0) 推荐(0)
摘要:There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[... 阅读全文
posted @ 2015-05-16 16:15 amazingzoe 阅读(241) 评论(0) 推荐(0)
摘要:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A s... 阅读全文
posted @ 2015-05-14 22:29 amazingzoe 阅读(143) 评论(0) 推荐(0)
摘要:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number... 阅读全文
posted @ 2015-05-14 21:52 amazingzoe 阅读(131) 评论(0) 推荐(0)