CodeReview->Lists&Array
文章平均质量分 72
amberFeb
这个作者很懒,什么都没留下…
展开
-
第9题 Median of Two Sorted Arrays
There 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)). Note:求两个sorted array的中间值,不是平均值哦。原创 2014-10-07 04:31:45 · 434 阅读 · 0 评论 -
第59题 Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Hide Tags Linked List原创 2015-05-09 17:31:50 · 268 阅读 · 0 评论 -
第62题 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, where原创 2015-05-09 18:53:20 · 263 阅读 · 0 评论 -
第60题 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Hide Tags Divide and Conquer Linked List Heap Code原创 2015-05-09 18:08:26 · 349 阅读 · 0 评论 -
第64题 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 exact原创 2015-05-09 23:30:25 · 394 阅读 · 0 评论 -
第61题 Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You m原创 2015-05-09 18:18:13 · 370 阅读 · 0 评论 -
第63题 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)原创 2015-05-09 22:14:03 · 312 阅读 · 0 评论 -
第65题 Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2015-05-10 00:22:19 · 249 阅读 · 0 评论 -
第66题 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原创 2015-05-10 00:45:57 · 377 阅读 · 0 评论 -
第58题 Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has原创 2015-05-09 01:35:10 · 273 阅读 · 0 评论 -
第67题 Subsets
Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets. For exampl原创 2015-05-10 01:18:26 · 339 阅读 · 0 评论 -
第73题 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very原创 2015-05-11 16:34:22 · 327 阅读 · 0 评论 -
第76题 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.top() -- Get原创 2015-05-11 18:20:53 · 354 阅读 · 0 评论 -
第49题 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit st原创 2015-03-18 01:29:34 · 261 阅读 · 0 评论 -
第23题 Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.原创 2014-10-15 14:08:40 · 261 阅读 · 0 评论 -
第七题 Linked List Cycle
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? Solution:原创 2014-10-06 05:57:03 · 385 阅读 · 0 评论 -
第10题 Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space? Solution:原创 2014-10-07 15:23:03 · 275 阅读 · 0 评论 -
第11题 Reorder List
Given a singly linked list L: 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 example, Given {1,2,3,4}, reorder it t原创 2014-10-08 10:54:35 · 420 阅读 · 0 评论 -
第十二题 Merge Sorted Array
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 to m + n) to hold additional elements fro原创 2014-10-09 13:36:32 · 514 阅读 · 0 评论 -
第13题 Add Two Numbers
You 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 link原创 2014-10-09 14:49:31 · 620 阅读 · 0 评论 -
第16&17题 Remove Duplicates from Sorted List
Remove Duplicates from Sorted List I Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3原创 2014-10-11 13:35:34 · 607 阅读 · 0 评论 -
第19题 Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2014-10-11 15:06:15 · 391 阅读 · 0 评论 -
第20题 Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy原创 2014-10-11 17:57:26 · 469 阅读 · 0 评论 -
第21题 Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of原创 2014-10-11 19:37:33 · 351 阅读 · 0 评论 -
第14&15题 Remove Duplicates from Sorted Array I&II
Remove Duplicates from Sorted Array I Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for an原创 2014-10-11 12:40:51 · 579 阅读 · 0 评论 -
第18题 Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. S原创 2014-10-11 14:38:21 · 559 阅读 · 0 评论 -
第22题 Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. Solution: /** * Definition for原创 2014-10-12 10:23:45 · 519 阅读 · 0 评论 -
第77题 Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest pr原创 2015-05-11 18:49:27 · 307 阅读 · 0 评论