# 直线上最多的点数

<p>给你一个数组 <code>points</code> ，其中 <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> 表示 <strong>X-Y</strong> 平面上的一个点。求最多有多少个点在同一条直线上。</p>

<p> </p>

<p><strong>示例 1：</strong></p>
<img alt="" src="https://img-service.csdnimg.cn/img_convert/69c636b932676fa16d04cf33e5936743.jpeg" style="width: 300px; height: 294px;" />
<pre>
<strong>输入：</strong>points = [[1,1],[2,2],[3,3]]
<strong>输出：</strong>3
</pre>

<p><strong>示例 2：</strong></p>
<img alt="" src="https://img-service.csdnimg.cn/img_convert/e969e8a2cebf3a9d164492986f185ad3.jpeg" style="width: 300px; height: 294px;" />
<pre>
<strong>输入：</strong>points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
<strong>输出：</strong>4
</pre>

<p> </p>

<p><strong>提示：</strong></p>

<ul>
	<li><code>1 <= points.length <= 300</code></li>
	<li><code>points[i].length == 2</code></li>
	<li><code>-10<sup>4</sup> <= x<sub>i</sub>, y<sub>i</sub> <= 10<sup>4</sup></code></li>
	<li><code>points</code> 中的所有点 <strong>互不相同</strong></li>
</ul>


## template

```java
class Solution {
	public int maxPoints(int[][] points) {
		int n = points.length;
		if (n == 0)
			return 0;
		if (n == 1)
			return 1;
		int res = 0;
		for (int i = 0; i < n - 1; i++) {
			Map<String, Integer> slope = new HashMap<>();
			int repeat = 0;
			int tmp_max = 0;
			for (int j = i + 1; j < n; j++) {
				int dy = points[i][1] - points[j][1];
				int dx = points[i][0] - points[j][0];
				if (dy == 0 && dx == 0) {
					repeat++;
					continue;
				}
				int g = gcd(dy, dx);
				if (g != 0) {
					dy /= g;
					dx /= g;
				}
				String tmp = String.valueOf(dy) + "/" + String.valueOf(dx);
				slope.put(tmp, slope.getOrDefault(tmp, 0) + 1);
				tmp_max = Math.max(tmp_max, slope.get(tmp));
			}
			res = Math.max(res, repeat + tmp_max + 1);
		}
		return res;
	}

	private int gcd(int dy, int dx) {
		if (dx == 0)
			return dy;
		else
			return gcd(dx, dy % dx);
	}
}


```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```