File tree 6 files changed +80
-0
lines changed
2683.Neighboring Bitwise XOR
6 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,24 @@ func sumOfPower(nums []int) (ans int) {
148
148
}
149
149
```
150
150
151
+ ### ** TypeScript**
152
+
153
+ ``` ts
154
+ function sumOfPower(nums : number []): number {
155
+ const mod = 10 ** 9 + 7 ;
156
+ nums .sort ((a , b ) => a - b );
157
+ let ans = 0 ;
158
+ let p = 0 ;
159
+ for (let i = nums .length - 1 ; i >= 0 ; -- i ) {
160
+ const x = BigInt (nums [i ]);
161
+ ans = (ans + Number ((x * x * x ) % BigInt (mod ))) % mod ;
162
+ ans = (ans + Number ((x * BigInt (p )) % BigInt (mod ))) % mod ;
163
+ p = Number ((BigInt (p ) * 2n + x * x ) % BigInt (mod ));
164
+ }
165
+ return ans ;
166
+ }
167
+ ```
168
+
151
169
### ** ...**
152
170
153
171
```
Original file line number Diff line number Diff line change @@ -121,6 +121,24 @@ func sumOfPower(nums []int) (ans int) {
121
121
}
122
122
```
123
123
124
+ ### ** TypeScript**
125
+
126
+ ``` ts
127
+ function sumOfPower(nums : number []): number {
128
+ const mod = 10 ** 9 + 7 ;
129
+ nums .sort ((a , b ) => a - b );
130
+ let ans = 0 ;
131
+ let p = 0 ;
132
+ for (let i = nums .length - 1 ; i >= 0 ; -- i ) {
133
+ const x = BigInt (nums [i ]);
134
+ ans = (ans + Number ((x * x * x ) % BigInt (mod ))) % mod ;
135
+ ans = (ans + Number ((x * BigInt (p )) % BigInt (mod ))) % mod ;
136
+ p = Number ((BigInt (p ) * 2n + x * x ) % BigInt (mod ));
137
+ }
138
+ return ans ;
139
+ }
140
+ ```
141
+
124
142
### ** ...**
125
143
126
144
```
Original file line number Diff line number Diff line change
1
+ function sumOfPower ( nums : number [ ] ) : number {
2
+ const mod = 10 ** 9 + 7 ;
3
+ nums . sort ( ( a , b ) => a - b ) ;
4
+ let ans = 0 ;
5
+ let p = 0 ;
6
+ for ( let i = nums . length - 1 ; i >= 0 ; -- i ) {
7
+ const x = BigInt ( nums [ i ] ) ;
8
+ ans = ( ans + Number ( ( x * x * x ) % BigInt ( mod ) ) ) % mod ;
9
+ ans = ( ans + Number ( ( x * BigInt ( p ) ) % BigInt ( mod ) ) ) % mod ;
10
+ p = Number ( ( BigInt ( p ) * 2n + x * x ) % BigInt ( mod ) ) ;
11
+ }
12
+ return ans ;
13
+ }
Original file line number Diff line number Diff line change @@ -141,6 +141,18 @@ func doesValidArrayExist(derived []int) bool {
141
141
}
142
142
```
143
143
144
+ ### ** TypeScript**
145
+
146
+ ``` ts
147
+ function doesValidArrayExist(derived : number []): boolean {
148
+ let s = 0 ;
149
+ for (const x of derived ) {
150
+ s ^= x ;
151
+ }
152
+ return s === 0 ;
153
+ }
154
+ ```
155
+
144
156
### ** ...**
145
157
146
158
```
Original file line number Diff line number Diff line change @@ -113,6 +113,18 @@ func doesValidArrayExist(derived []int) bool {
113
113
}
114
114
```
115
115
116
+ ### ** TypeScript**
117
+
118
+ ``` ts
119
+ function doesValidArrayExist(derived : number []): boolean {
120
+ let s = 0 ;
121
+ for (const x of derived ) {
122
+ s ^= x ;
123
+ }
124
+ return s === 0 ;
125
+ }
126
+ ```
127
+
116
128
### ** ...**
117
129
118
130
```
Original file line number Diff line number Diff line change
1
+ function doesValidArrayExist ( derived : number [ ] ) : boolean {
2
+ let s = 0 ;
3
+ for ( const x of derived ) {
4
+ s ^= x ;
5
+ }
6
+ return s === 0 ;
7
+ }
You can’t perform that action at this time.
0 commit comments