interview question
文章平均质量分 80
Jasmine开心地学习
这个作者很懒,什么都没留下…
展开
-
last position of target / first position of target
Last Position of TargetFind the last position of a target number in a sorted array. Return -1 if target does not exist.O(log n)public class Solution { /** * @param nums: An integer arra原创 2016-12-13 10:27:52 · 320 阅读 · 0 评论 -
Sort List
Sort a linked list in O(n log n) time using constant space complexity.Merge sort/** * Definition for ListNode. * public class ListNode { * int val; * ListNode next; * ListNo原创 2016-12-14 14:11:50 · 124 阅读 · 0 评论 -
Subarray Sum
Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the last number. NoticeThere is at least one原创 2016-12-14 15:26:46 · 178 阅读 · 0 评论 -
Maximum Subarray
Given an array of integers, find a contiguous subarray which has the largest sum. NoticeThe subarray should contain at least one number.ExampleGiven the array [−2,2,−3,4,−1,2,1,−5,转载 2016-12-14 15:45:58 · 116 阅读 · 0 评论 -
Subarray Sum Closest
Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number.ExampleGiven [-3, 1, 1, -3, 5], return [0, 2], [1, 3], [1, 1], [2原创 2016-12-14 16:14:24 · 154 阅读 · 0 评论 -
Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. NoticeYou may assume that duplicates do not exist in the tree.Given inorder [1,2,3] and postorder [1,3原创 2016-12-21 10:35:46 · 198 阅读 · 0 评论 -
Delete Node in the Middle of Singly Linked List
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.ExampleGiven 1->2->3->4, and node 3. return 1->2->4/** * Definition for原创 2016-12-21 10:52:52 · 186 阅读 · 0 评论 -
Swap Two Nodes in Linked List
Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 and v2. It's guaranteed there is no duplicate values in the linked list. If v1 or v2 does not exist i原创 2016-12-21 13:42:22 · 205 阅读 · 0 评论 -
Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.ExampleGiven 1->2->3->4->5 and k = 2, return 4->5->1->2->3./** * Definition for singly-linked lis原创 2016-12-21 14:23:14 · 190 阅读 · 0 评论 -
Complete Binary Tree
Check a binary tree is completed or not. A complete binary tree is a binary tree that every level is completed filled except the deepest level. In the deepest level, all nodes must be as left as possi原创 2016-12-20 10:32:49 · 237 阅读 · 0 评论 -
Subsets vs Permutations
SubsetsGiven a set of distinct integers, return all possible subsets. NoticeElements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.原创 2016-12-16 16:48:06 · 181 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list.Analyze and describe its complexity.ExampleGiven lists:[ 2->4->null, null, -1->null],return -1->2->4-原创 2016-12-14 12:10:45 · 209 阅读 · 0 评论 -
Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2016-12-16 11:47:59 · 136 阅读 · 0 评论 -
Search in a Big Sorted Array
Given a big sorted array with positive integers sorted by ascending order. The array is so big so that you can not get the length of the whole array directly, and you can only access the kth number by原创 2016-12-13 10:42:05 · 922 阅读 · 0 评论 -
Wood Cut
Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you could have equal or more than k pieces with the same length. What is the longest length you can g原创 2016-12-13 10:44:48 · 196 阅读 · 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. NoticeYou may assume no原创 2016-12-13 10:50:35 · 145 阅读 · 0 评论 -
Find Peak Element
There is an integer array which has the following features:The numbers in adjacent positions are different.A[0] A[A.length - 1].We define a position P is a peek if:A[P] > A[P-1] && A[P]原创 2016-12-13 10:52:28 · 403 阅读 · 0 评论 -
Search 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).You are given a target value to search. If found in the array retur原创 2016-12-13 11:18:44 · 112 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree./** * Definition of TreeNode: * public class TreeNode { * public int val; * pu原创 2016-12-13 14:49:05 · 252 阅读 · 0 评论 -
Inorder Successor in Binary Search Tree
Given a binary search tree (See Definition) and a node in it, find the in-order successor of that node in the BST.If the given node has no in-order successor in the tree, return null.原创 2016-12-13 14:45:31 · 177 阅读 · 0 评论 -
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原创 2016-12-14 11:17:04 · 128 阅读 · 0 评论 -
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./** * Definition for singly-lin原创 2016-12-14 11:53:24 · 133 阅读 · 0 评论 -
Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. NoticeYou may assume that duplicates do not exist in the tree.ExampleGiven in-order [1,2,3] and pre-order原创 2016-12-20 15:58:10 · 207 阅读 · 0 评论