File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
solution/2000-2099/2064.Minimized Maximum of Products Distributed to Any Store Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 6666
6767<!-- 这里可写通用的实现逻辑 -->
6868
69+ 二分法
70+
6971<!-- tabs:start -->
7072
7173### ** Python3**
8486
8587```
8688
89+ ### ** TypeScript**
90+
91+ ``` ts
92+ function minimizedMaximum(n : number , quantities : number []): number {
93+ const m = quantities .length ;
94+ let left = 1 , right = Math .max (... quantities );
95+ while (left <= right ) {
96+ let mid = (left + right ) >> 1 ;
97+ let sum = 0 ;
98+ for (let num of quantities ) {
99+ let cur = Math .floor ((num - 1 ) / mid ) + 1 ;
100+ sum += cur ;
101+ }
102+ if (sum > n ) {
103+ left = mid + 1 ;
104+ } else {
105+ right = mid - 1 ;
106+ }
107+ }
108+ return left ;
109+ };
110+ ```
111+
87112### ** ...**
88113
89114```
Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ The maximum number of products given to any store is max(100000) = 100000.
6060
6161## Solutions
6262
63+ Binary search.
64+
6365<!-- tabs:start -->
6466
6567### ** Python3**
@@ -74,6 +76,29 @@ The maximum number of products given to any store is max(100000) = 100000.
7476
7577```
7678
79+ ### ** TypeScript**
80+
81+ ``` ts
82+ function minimizedMaximum(n : number , quantities : number []): number {
83+ const m = quantities .length ;
84+ let left = 1 , right = Math .max (... quantities );
85+ while (left <= right ) {
86+ let mid = (left + right ) >> 1 ;
87+ let sum = 0 ;
88+ for (let num of quantities ) {
89+ let cur = Math .floor ((num - 1 ) / mid ) + 1 ;
90+ sum += cur ;
91+ }
92+ if (sum > n ) {
93+ left = mid + 1 ;
94+ } else {
95+ right = mid - 1 ;
96+ }
97+ }
98+ return left ;
99+ };
100+ ```
101+
77102### ** ...**
78103
79104```
Original file line number Diff line number Diff line change 1+ function minimizedMaximum ( n : number , quantities : number [ ] ) : number {
2+ const m = quantities . length ;
3+ let left = 1 , right = Math . max ( ...quantities ) ;
4+ while ( left <= right ) {
5+ let mid = ( left + right ) >> 1 ;
6+ let sum = 0 ;
7+ for ( let num of quantities ) {
8+ let cur = Math . floor ( ( num - 1 ) / mid ) + 1 ;
9+ sum += cur ;
10+ }
11+ if ( sum > n ) {
12+ left = mid + 1 ;
13+ } else {
14+ right = mid - 1 ;
15+ }
16+ }
17+ return left ;
18+ } ;
You can’t perform that action at this time.
0 commit comments