LeetCode 五月挑战专题每日随缘更新，点击类别 2020 May LeetCoding Challenge 查看更多。

## May 8th: Check If It Is a Straight Line

You are given an array `coordinates`, `coordinates[i] = [x, y]`, where `[x, y]` represents the coordinate of a point. Check if these points make a straight line in the XY plane.

Example 1:

Example 2:

Constraints:

• `2 <= coordinates.length <= 1000`

• `coordinates[i].length == 2`

• `-10^4 <= coordinates[i], coordinates[i] <= 10^4`

• `coordinates` contains no duplicate point.

## May 9th: Valid Perfect Square

Given a positive integer `num`, write a function which returns True if `num` is a perfect square else False.

Note: Do not use any built-in library function such as `sqrt`.

Example 1:

Example 2:

## May 10th: Find the Town Judge

In a town, there are `N` people labelled from `1` to `N`. There is a rumor that one of these people is secretly the town judge.

If the town judge exists, then:

1. The town judge trusts nobody.

2. Everybody (except for the town judge) trusts the town judge.

3. There is exactly one person that satisfies properties 1 and 2.

You are given `trust`, an array of pairs `trust[i] = [a, b]` representing that the person labelled `a` trusts the person labelled `b`.

If the town judge exists and can be identified, return the label of the town judge. Otherwise, return `-1`.

Example 1:

Example 2:

Example 3:

Example 4:

Example 5:

Note:

• `1 <= N <= 1000`

• `trust.length <= 10000`

• `trust[i]` are all different

• `trust[i] != trust[i]`

• `1 <= trust[i], trust[i] <= N`

## May 11th: Flood Fill

An `image` is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).

Given a coordinate `(sr, sc)` representing the starting pixel (row and column) of the flood fill, and a pixel value `newColor`, “flood fill” the image.

To perform a “flood fill”, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color as the starting pixel), and so on. Replace the color of all of the aforementioned pixels with the newColor.

At the end, return the modified image.

Example 1:

Note:

• The length of `image` and `image` will be in the range `[1, 50]`.

• The given starting pixel will satisfy `0 <= sr < image.length` and `0 <= sc < image.length`.

• The value of each color in `image[i][j]` and `newColor` will be an integer in `[0, 65535]`.

## May 12th: Single Element in a Sorted Array

You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only once.

Example 1:

Example 2:

Note: Your solution should run in O(log n) time and O(1) space.

### 题目解析

• 对于数字 `num` 来说，`num ^ num == 0`

• 对于数字 `num` 来说，`num ^ 0 == num`

## May 13th: Remove K Digits

Given a non-negative integer `num` represented as a string, remove `k` digits from the number so that the new number is the smallest possible.

Note:

• The length of `num` is less than 10002 and will be ≥ `k`.

• The given `num` does not contain any leading zero.

Example 1:

Example 2:

Example 3:

### 题目解析

`num` 中的字符逐个添加到 `res` 中，为了保证高位上的数字尽可能地小，在添加过程中需要去除 `res` 中比当前字符大的字符，从而保证 `res` 是非递减的。

## May 14th: Implement Trie (Prefix Tree)

Implement a trie with `insert`, `search`, and `startsWith` methods.

Example:

Note:

• You may assume that all inputs are consist of lowercase letters `a-z`.

• All inputs are guaranteed to be non-empty strings.

### 题目解析

#### C++ 实现 微信 支付宝