File tree Expand file tree Collapse file tree 4 files changed +37
-3
lines changed
1636.Sort Array by Increasing Frequency
1637.Widest Vertical Area Between Two Points Containing No Points Expand file tree Collapse file tree 4 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 46
46
47
47
** 方法一:数组或哈希表计数**
48
48
49
- 用数组或者哈希表统计 ` nums ` 中每个数字出现的次数,由于题目中数字的范围是 ` [-100, 100] ` ,我们可以直接创建一个大小为 $201$ 的数组来统计。
49
+ 用数组或者哈希表统计 ` nums ` 中每个数字出现的次数,由于题目中数字的范围是 $ [ -100, 100] $ ,我们可以直接创建一个大小为 $201$ 的数组来统计。
50
50
51
51
然后对 ` nums ` 按照数字出现次数升序排序,如果出现次数相同,则按照数字降序排序。
52
52
53
- 时间复杂度为 $O(n\ log n)$,空间复杂度 $O(n)$。其中 $n$ 为 ` nums ` 的长度。
53
+ 时间复杂度为 $O(n \times \ log n)$,空间复杂度 $O(n)$。其中 $n$ 为数组 ` nums ` 的长度。
54
54
55
55
<!-- tabs:start -->
56
56
Original file line number Diff line number Diff line change 46
46
47
47
** 方法一:排序**
48
48
49
- 对 ` points ` 按照 $x$ 升序排列,获取相邻点之间 $x$ 的差值的最大值。
49
+ 我们可以对 ` points ` 按照 $x$ 升序排列,获取相邻点之间 $x$ 的差值的最大值。
50
50
51
51
时间复杂度 $O(n \times \log n)$,空间复杂度 $O(\log n)$。其中 $n$ 为 ` points ` 的长度。
52
52
@@ -115,6 +115,19 @@ func max(a, b int) int {
115
115
}
116
116
```
117
117
118
+ ### ** TypeScript**
119
+
120
+ ``` ts
121
+ function maxWidthOfVerticalArea(points : number [][]): number {
122
+ points .sort ((a , b ) => a [0 ] - b [0 ]);
123
+ let ans = 0 ;
124
+ for (let i = 1 ; i < points .length ; ++ i ) {
125
+ ans = Math .max (ans , points [i ][0 ] - points [i - 1 ][0 ]);
126
+ }
127
+ return ans ;
128
+ }
129
+ ```
130
+
118
131
### ** JavaScript**
119
132
120
133
``` js
Original file line number Diff line number Diff line change @@ -99,6 +99,19 @@ func max(a, b int) int {
99
99
}
100
100
```
101
101
102
+ ### ** TypeScript**
103
+
104
+ ``` ts
105
+ function maxWidthOfVerticalArea(points : number [][]): number {
106
+ points .sort ((a , b ) => a [0 ] - b [0 ]);
107
+ let ans = 0 ;
108
+ for (let i = 1 ; i < points .length ; ++ i ) {
109
+ ans = Math .max (ans , points [i ][0 ] - points [i - 1 ][0 ]);
110
+ }
111
+ return ans ;
112
+ }
113
+ ```
114
+
102
115
### ** JavaScript**
103
116
104
117
``` js
Original file line number Diff line number Diff line change
1
+ function maxWidthOfVerticalArea ( points : number [ ] [ ] ) : number {
2
+ points . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) ;
3
+ let ans = 0 ;
4
+ for ( let i = 1 ; i < points . length ; ++ i ) {
5
+ ans = Math . max ( ans , points [ i ] [ 0 ] - points [ i - 1 ] [ 0 ] ) ;
6
+ }
7
+ return ans ;
8
+ }
You can’t perform that action at this time.
0 commit comments