Leetcode Diary

62.63.64 Unique Paths(I,II,III)

Leetcode Diary

62 A 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 ...

61. Rotate List

Leetcode Diary

Given a linked list, rotate the list to the right by k places, where k is non-negative. Example Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->2->3->NULL Exp...

60. Permutation Sequence

Leetcode Diary

The 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 for n = 3: “123” “132” “213”...

59. Spiral Matrix II

Leetcode Diary

GGiven a positive integer n, generate a square matrix filled with elements from 1 to n^2 in spiral order. Example Input: 3 Output: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ] Thoughts ...

58. Length of Last Word

Leetcode Diary

Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘, return the length of last word (last word means the last appearing word if we loop from left to right) in ...

57. Insert Interval

Leetcode Diary

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times...

56. Merge Intervals

Leetcode Diary

Given a collection of intervals, merge all overlapping intervals. intervals[i][0] <= intervals[i][1] Example: Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,1...

55. Jump Game

Leetcode Diary

Given 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. Deter...

54. Spiral Matrix

Leetcode Diary

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7,4,...

53. Maximum Subarray

Leetcode Diary

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Follow up: If you have figured out the O(n) solution, ...