描述
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorte
...
描述
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorte
...
描述
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
...
描述
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
...
描述
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 re
...
描述
Given an unsorted integer array, find the first missing positive integer.
For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.
Your algorith
...
描述
Sort a linked list in O(n log n) time using constant space complexity.
分析要求时间O(nlogn),上一题的插入排序就不能用了,可以使用归并排序,先split成两个链表,分别递归排序,再归并。可以用到我们之前的Merge
...
描述
Sort a linked list using insertion sort.
分析链表的插入排序,不难,但程序写对不容易。
代码总是超时的解,发誓逻辑是对的1234567891011121314151617181920212223class Solution(object): d
...
描述
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
分析和上一题思路是一样的,不过简单的按顺序合并提交会超时,要想办法加速。空间换时间,利用一个h
...
描述
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.
分析和合
...
描述
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
Note:You may assume that nums1 has enough space (size
...
描述
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.
An example is the root-to-leaf path 1->2-&
...
描述
Given a binary tree, find the maximum path sum.
The path may start and end at any node in the tree.
For example:Given the below binary tree,
1
/
...
描述
Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.
For example:Given the below binary tree and
...
描述
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum
...