0%

Description

Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.

Example:

1
2
3
4
5
6
7
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]

Difficulty: Medium

Code:

1
2
3
4
5
class Solution {
public int[][] generateMatrix(int n) {

}
}

题意

给定正整数n,生成一个正方形矩阵,用从1到n的平方以螺旋到方式进行填充。

阅读全文 »

Description

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
2
Input: "Hello World"
Output: 5

Difficulty: Easy

Code:

1
2
3
4
5
class Solution {
public int lengthOfLastWord(String s) {

}
}

题意

给定一个字符串包含大小写字母和空格,返回最后一个单词的长度。

阅读全文 »

Description

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
2
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
Output: [[1,5],[6,9]]

Example 2:

1
2
3
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
Output: [[1,2],[3,10],[12,16]]
Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].

Difficulty: Hard

Code:

1
2
3
4
5
class Solution {
public int[][] insert(int[][] intervals, int[] newInterval) {

}
}

题意

给定一系列非重叠对区间,然后插入一个新区间,若和原有区间重叠,则要进行合并操作。

阅读全文 »

案发现场

昨天晚上突然短信收到 APM (即 Application Performance Management 的简称),我们内部自己搭建了这样一套系统来对应用的性能、可靠性进行线上的监控和预警的一种机制)大量告警
画外音: 监控是一种非常重要的发现问题的手段,没有的话一定要及时建立哦

紧接着运维打来电话告知线上部署的四台机器全部 OOM (out of memory, 内存不足),服务全部不可用,赶紧查看问题!

阅读全文 »

Description

Given a collection of intervals, merge all overlapping intervals.

Example 1:

1
2
3
Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].

Example 2:

1
2
3
Input: [[1,4],[4,5]]
Output: [[1,5]]
Explanation: Intervals [1,4] and [4,5] are considered overlapping.

Difficulty: Medium

Code:

1
2
3
4
5
class Solution {
public int[][] merge(int[][] intervals) {

}
}

题意

给定一组区间,要求合并所有重叠的区间。

阅读全文 »