首頁

0

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

0

Remove Duplicates from Sorted Array II

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

0

Word Search

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

0

Subsets

SubsetsGiven a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example:If nums = [1,2,3], a solution is: 12345678910[ [3],

0

Combinations

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], [

0

Sort Colors

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

0

Search a 2D Matrix

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

0

Set Matrix Zeroes

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

0

Sqrt(x)

Sqrt(x)Implement int sqrt(int x). Compute and return the square root of x. 提示 解題應用 Math 規律觀查 Default:123func mySqrt(x int) int {} 解答思路:這題姑且只用最簡單的方式去解決,當然有人用牛頓法的方法來找出結果,不過一開始我就是只用最

0

Simplify Path

Simplify PathGiven an absolute path for a file (Unix-style), simplify it. For example:12path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c" 提

0

Minimum Path Sum

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

0

Unique Paths II

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

0

Unique Paths

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

0

Rotate List

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.

0

Permutation Sequence

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

0

Spiral Matrix II

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 ], [

0

Merge Intervals

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

0

Jump Game

Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determi

0

Spiral Matrix

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,

0

Maximum Subarray

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 [

0

Pow(x, n)

Pow(x, n)Implement pow(x, n). 提示 解題應用 BinarySearch 二分法 Math 規律觀查 Default:123func myPow(x float64, n int) float64 {} 解答思路:先考慮次方值n只有正數的情況下,如果n是偶數的話x^n就可以變成(x*x)^(n/2),也就是說每次的次方數都可

0

Group Anagrams

Group AnagramsGiven an array of strings, group anagrams together. For example:Given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],Return: 12345[ ["ate", "eat","tea"], [&