Skip to content

Commit 850ea49

Browse files
authored
feat: add solutions to lc problems: No.2681,2683 (doocs#1324)
* No.2681.Power of Heroes * No.2683.Neighboring Bitwise XOR
1 parent f4fc2fa commit 850ea49

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

solution/2600-2699/2681.Power of Heroes/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,24 @@ func sumOfPower(nums []int) (ans int) {
148148
}
149149
```
150150

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+
151169
### **...**
152170

153171
```

solution/2600-2699/2681.Power of Heroes/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ func sumOfPower(nums []int) (ans int) {
121121
}
122122
```
123123

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+
124142
### **...**
125143

126144
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

solution/2600-2699/2683.Neighboring Bitwise XOR/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ func doesValidArrayExist(derived []int) bool {
141141
}
142142
```
143143

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+
144156
### **...**
145157

146158
```

solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md

+12
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ func doesValidArrayExist(derived []int) bool {
113113
}
114114
```
115115

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+
116128
### **...**
117129

118130
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
}

0 commit comments

Comments
 (0)