Skip to content

Commit 9ae12d5

Browse files
committed
feat: add typescript solution to lc problem: No.2280
No.2280.Minimum Lines to Represent a Line Chart
1 parent 5f5cd64 commit 9ae12d5

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,20 @@ func minimumLines(stockPrices [][]int) int {
149149
### **TypeScript**
150150

151151
```ts
152-
152+
function minimumLines(stockPrices: number[][]): number {
153+
const n = stockPrices.length;
154+
stockPrices.sort((a, b) => a[0] - b[0]);
155+
let ans = 0;
156+
let pre = [BigInt(0), BigInt(0)];
157+
for (let i = 1; i < n; i++) {
158+
const [x1, y1] = stockPrices[i - 1];
159+
const [x2, y2] = stockPrices[i];
160+
const dx = BigInt(x2 - x1), dy = BigInt(y2 - y1);
161+
if (i == 1 || (dx * pre[1] !== dy * pre[0])) ans++;
162+
pre = [dx, dy];
163+
}
164+
return ans;
165+
};
153166
```
154167

155168
### **...**

solution/2200-2299/2280.Minimum Lines to Represent a Line Chart/README_EN.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,20 @@ func minimumLines(stockPrices [][]int) int {
131131
### **TypeScript**
132132

133133
```ts
134-
134+
function minimumLines(stockPrices: number[][]): number {
135+
const n = stockPrices.length;
136+
stockPrices.sort((a, b) => a[0] - b[0]);
137+
let ans = 0;
138+
let pre = [BigInt(0), BigInt(0)];
139+
for (let i = 1; i < n; i++) {
140+
const [x1, y1] = stockPrices[i - 1];
141+
const [x2, y2] = stockPrices[i];
142+
const dx = BigInt(x2 - x1), dy = BigInt(y2 - y1);
143+
if (i == 1 || (dx * pre[1] !== dy * pre[0])) ans++;
144+
pre = [dx, dy];
145+
}
146+
return ans;
147+
};
135148
```
136149

137150
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function minimumLines(stockPrices: number[][]): number {
2+
const n = stockPrices.length;
3+
stockPrices.sort((a, b) => a[0] - b[0]);
4+
let ans = 0;
5+
let pre = [BigInt(0), BigInt(0)];
6+
for (let i = 1; i < n; i++) {
7+
const [x1, y1] = stockPrices[i - 1];
8+
const [x2, y2] = stockPrices[i];
9+
const dx = BigInt(x2 - x1), dy = BigInt(y2 - y1);
10+
if (i == 1 || (dx * pre[1] !== dy * pre[0])) ans++;
11+
pre = [dx, dy];
12+
}
13+
return ans;
14+
};

0 commit comments

Comments
 (0)