File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
solution/0800-0899/0888.Fair Candy Swap Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,22 @@ class Solution {
109
109
}
110
110
```
111
111
112
+ ### ** TypeScript**
113
+
114
+ ``` ts
115
+ function fairCandySwap(aliceSizes : number [], bobSizes : number []): number [] {
116
+ let s1 = aliceSizes .reduce ((a , c ) => a + c , 0 );
117
+ let s2 = bobSizes .reduce ((a , c ) => a + c , 0 );
118
+ let diff = (s1 - s2 ) >> 1 ;
119
+ for (let num of aliceSizes ) {
120
+ let target = num - diff ;
121
+ if (bobSizes .includes (target )) {
122
+ return [num , target ];
123
+ }
124
+ }
125
+ };
126
+ ```
127
+
112
128
### ** C++**
113
129
114
130
``` cpp
Original file line number Diff line number Diff line change @@ -158,6 +158,22 @@ class Solution {
158
158
}
159
159
```
160
160
161
+ ### ** TypeScript**
162
+
163
+ ``` ts
164
+ function fairCandySwap(aliceSizes : number [], bobSizes : number []): number [] {
165
+ let s1 = aliceSizes .reduce ((a , c ) => a + c , 0 );
166
+ let s2 = bobSizes .reduce ((a , c ) => a + c , 0 );
167
+ let diff = (s1 - s2 ) >> 1 ;
168
+ for (let num of aliceSizes ) {
169
+ let target = num - diff ;
170
+ if (bobSizes .includes (target )) {
171
+ return [num , target ];
172
+ }
173
+ }
174
+ };
175
+ ```
176
+
161
177
### ** C++**
162
178
163
179
``` cpp
Original file line number Diff line number Diff line change
1
+ function fairCandySwap ( aliceSizes : number [ ] , bobSizes : number [ ] ) : number [ ] {
2
+ let s1 = aliceSizes . reduce ( ( a , c ) => a + c , 0 ) ;
3
+ let s2 = bobSizes . reduce ( ( a , c ) => a + c , 0 ) ;
4
+ let diff = ( s1 - s2 ) >> 1 ;
5
+ for ( let num of aliceSizes ) {
6
+ let target = num - diff ;
7
+ if ( bobSizes . includes ( target ) ) {
8
+ return [ num , target ] ;
9
+ }
10
+ }
11
+ } ;
You can’t perform that action at this time.
0 commit comments