Search in Rotated Sorted Array II
Search in Rotated Sorted Array II Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose an array sorted in a
Search in Rotated Sorted Array II Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose an array sorted in a
Remove Duplicates from Sorted Array IIFollow up for “Remove Duplicates”:What if duplicates are allowed at most twice? For example:123Given sorted array nums = [1,1,1,2,2,3],Your function should retur
Word SearchGiven a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or v
CombinationsGiven two integers n and k, return all possible combinations of k numbers out of 1 … n. For example:If n = 4 and k = 2, a solution is: 12345678[ [2,4], [3,4], [2,3], [1,2], [1,3], [
Sort ColorsGiven 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
Search a 2D MatrixWrite 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 sorted from left to right. The first i
Set Matrix ZeroesGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space? A straight forward solution using O(mn) space is pro
Simplify PathGiven an absolute path for a file (Unix-style), simplify it. For example:12path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c" 提
Minimum Path SumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either do
Unique Paths IIFollow 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 space is marked as 1 and 0 respectively
Unique PathsA robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to
Rotate ListGiven a list, rotate the list to the right by k places, where k is non-negative. For example:12Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.
Permutation SequenceThe set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): “123” “132
Spiral Matrix IIGiven an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example:Given n = 3, You should return the following matrix: 12345[ [ 1, 2, 3 ], [
Merge IntervalsGiven a collection of intervals, merge all overlapping intervals. For example:12Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]. 提示 解題應用 Array Array/Slice Sort In
Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example:Given the following matrix: 12345[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8,
Maximum SubarrayFind 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 [
Group AnagramsGiven an array of strings, group anagrams together. For example:Given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],Return: 12345[ ["ate", "eat","tea"], [&