Description
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
1 | Input: 3 |
Difficulty: Medium
Code:
1 | class Solution { |
题意
给定正整数n,生成一个正方形矩阵,用从1到n的平方以螺旋到方式进行填充。
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
1 | Input: 3 |
Difficulty: Medium
Code:
1 | class Solution { |
给定正整数n,生成一个正方形矩阵,用从1到n的平方以螺旋到方式进行填充。
Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘, return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.
Example:
1 | Input: "Hello World" |
Difficulty: Easy
Code:
1 | class Solution { |
给定一个字符串包含大小写字母和空格,返回最后一个单词的长度。
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.
Example 1:
1 | Input: intervals = [[1,3],[6,9]], newInterval = [2,5] |
Example 2:
1 | Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8] |
Difficulty: Hard
Code:
1 | class Solution { |
给定一系列非重叠对区间,然后插入一个新区间,若和原有区间重叠,则要进行合并操作。
Given a collection of intervals, merge all overlapping intervals.
Example 1:
1 | Input: [[1,3],[2,6],[8,10],[15,18]] |
Example 2:
1 | Input: [[1,4],[4,5]] |
Difficulty: Medium
Code:
1 | class Solution { |
给定一组区间,要求合并所有重叠的区间。