摘要:思路:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction ...
阅读全文
摘要:题目:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints ...
阅读全文
摘要:题目:Follow upfor "Find Minimum in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Suppose a s...
阅读全文
摘要:题目:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note...
阅读全文
摘要:题目: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).Find the minimum element.Yo...
阅读全文
摘要:题目: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 ...
阅读全文
摘要:题目:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted fro...
阅读全文
摘要:题目:与上一道题几乎相同;不同之处在于array中允许有重复元素;但题目要求也简单了,只要返回true or falsehttp://www.cnblogs.com/xbf9xbf/p/4254590.html代码:oj测试通过Runtime:73 ms 1 class Solution: 2 ...
阅读全文
摘要:题目: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 valu...
阅读全文
摘要:题目:Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending ord...
阅读全文
摘要:题目:Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not...
阅读全文
摘要:题目:Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining...
阅读全文
摘要:题目:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the ...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty spac...
阅读全文
摘要:题目:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any poi...
阅读全文
摘要:题目: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?...
阅读全文
摘要:题目: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,...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its ind...
阅读全文
摘要:题目:Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the ...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目: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 eq...
阅读全文
摘要:题目:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?代码:oj测试通过Runtime...
阅读全文
摘要:题目:Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onl...
阅读全文
摘要:题目:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4...
阅读全文
摘要:题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is...
阅读全文
摘要:题目:Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should ...
阅读全文
摘要:题目:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space fo...
阅读全文
摘要:题目: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 ...
阅读全文
摘要:题目: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 sing...
阅读全文
摘要:题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.代码:oj测试通过Runtime:178 ms 1 # Definition...
阅读全文
摘要:题目: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 co...
阅读全文
摘要:题目:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.代码:oj测试通过Runtime:231 ms 1 # Definition for singly-l...
阅读全文
摘要:题目: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 or...
阅读全文
摘要:题目: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 al...
阅读全文
摘要:题目:Given a singly linked 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 e...
阅读全文
摘要:原题:Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen lef...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:Sort a linked list inO(nlogn) time using constant space complexity.代码:oj 测试通过Runtime:372 ms 1 # Definition for singly-linked list. 2 # class ListNo...
阅读全文
摘要:题目:Sort a linked list using insertion sort.代码:oj测试通过Runtime:860 ms 1 # Definition for singly-linked list. 2 # class ListNode: 3 # def __init__(sel...
阅读全文
摘要:公司和学校事情比较多,隔了好几天没刷题,今天继续刷起来。题目:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve i...
阅读全文