Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
- [乘积小于 K 的子数组](/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README.md) - `双指针`
- [位 1 的个数](/solution/0100-0199/0191.Number%20of%201%20Bits/README.md) - `位运算`、`lowbit`
- [合并区间](/solution/0000-0099/0056.Merge%20Intervals/README.md) - `区间合并`
<!-- 排序算法、待补充 -->
<!-- 排序算法、待补充 -->

### 2. 数据结构

Expand Down
4 changes: 2 additions & 2 deletions solution/0400-0499/0401.Binary Watch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ func readBinaryWatch(turnedOn int) []string {
function readBinaryWatch(turnedOn: number): string[] {
const ans: string[] = [];

for (let i = 0; i < (1 << 10); ++i) {
for (let i = 0; i < 1 << 10; ++i) {
const h = i >> 6;
const m = i & 0b111111;

if (h < 12 && m < 60 && bitCount(i) === turnedOn) {
ans.push(`${h}:${m < 10 ? "0" : ""}${m}`);
ans.push(`${h}:${m < 10 ? '0' : ''}${m}`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions solution/0400-0499/0401.Binary Watch/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ func readBinaryWatch(turnedOn int) []string {
function readBinaryWatch(turnedOn: number): string[] {
const ans: string[] = [];

for (let i = 0; i < (1 << 10); ++i) {
for (let i = 0; i < 1 << 10; ++i) {
const h = i >> 6;
const m = i & 0b111111;

if (h < 12 && m < 60 && bitCount(i) === turnedOn) {
ans.push(`${h}:${m < 10 ? "0" : ""}${m}`);
ans.push(`${h}:${m < 10 ? '0' : ''}${m}`);
}
}

Expand Down
6 changes: 3 additions & 3 deletions solution/0400-0499/0401.Binary Watch/Solution2.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function readBinaryWatch(turnedOn: number): string[] {
const ans: string[] = [];

for (let i = 0; i < (1 << 10); ++i) {
for (let i = 0; i < 1 << 10; ++i) {
const h = i >> 6;
const m = i & 0b111111;

if (h < 12 && m < 60 && bitCount(i) === turnedOn) {
ans.push(`${h}:${m < 10 ? "0" : ""}${m}`);
ans.push(`${h}:${m < 10 ? '0' : ''}${m}`);
}
}

Expand All @@ -20,4 +20,4 @@ function bitCount(i: number): number {
i = i + (i >>> 8);
i = i + (i >>> 16);
return i & 0x3f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func hasAlternatingBits(n int) bool {

```ts
function hasAlternatingBits(n: number): boolean {
n ^= (n >> 1);
n ^= n >> 1;
return (n & (n + 1)) === 0;
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func hasAlternatingBits(n int) bool {

```ts
function hasAlternatingBits(n: number): boolean {
n ^= (n >> 1);
n ^= n >> 1;
return (n & (n + 1)) === 0;
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function hasAlternatingBits(n: number): boolean {
n ^= (n >> 1);
n ^= n >> 1;
return (n & (n + 1)) === 0;
}
2 changes: 1 addition & 1 deletion solution/0600-0699/0696.Count Binary Substrings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function countBinarySubstrings(s: string): number {
}

return ans;
};
}
```

#### Rust
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ function countBinarySubstrings(s: string): number {
}

return ans;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ impl Solution {
}
```

#### C#

```cs
public class Solution {
public int CountPrimeSetBits(int left, int right) {
var primes = new HashSet<int> { 2, 3, 5, 7, 11, 13, 17, 19 };
int ans = 0;

for (int i = left; i <= right; ++i) {
int bits = BitOperations.PopCount((uint)i);
if (primes.Contains(bits)) {
++ans;
}
}

return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ impl Solution {
}
```

#### C#

```cs
public class Solution {
public int CountPrimeSetBits(int left, int right) {
var primes = new HashSet<int> { 2, 3, 5, 7, 11, 13, 17, 19 };
int ans = 0;

for (int i = left; i <= right; ++i) {
int bits = BitOperations.PopCount((uint)i);
if (primes.Contains(bits)) {
++ans;
}
}

return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Solution {
public int CountPrimeSetBits(int left, int right) {
var primes = new HashSet<int> { 2, 3, 5, 7, 11, 13, 17, 19 };
int ans = 0;

for (int i = left; i <= right; ++i) {
int bits = BitOperations.PopCount((uint)i);
if (primes.Contains(bits)) {
++ans;
}
}

return ans;
}
}
2 changes: 2 additions & 0 deletions solution/3800-3899/3838.Weighted Word Mapping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3838.Weighted%20Word%20Mapping/README.md
rating: 1240
source: 第 176 场双周赛 Q1
---

<!-- problem:start -->
Expand Down
10 changes: 6 additions & 4 deletions solution/3800-3899/3838.Weighted Word Mapping/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3838.Weighted%20Word%20Mapping/README_EN.md
rating: 1240
source: Biweekly Contest 176 Q1
---

<!-- problem:start -->
Expand Down Expand Up @@ -84,16 +86,16 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3838.We

<!-- description:end -->

## Solutions

<!-- solution:start -->

### Solution 1: Simulation

We iterate through each word $w$ in $\textit{words}$, calculate its weight $s$, which is the sum of the weights of all characters in the word. Then we calculate $s$ modulo 26, map the result to a lowercase English letter, and finally concatenate all the mapped characters and return.

The time complexity is $O(L)$, where $L$ is the sum of the lengths of all words in $\textit{words}$. The space complexity is $O(W)$, where $W$ is the length of $\textit{words}$.

<!-- solution:start -->

### Solution 1

<!-- tabs:start -->

#### Python3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3839.Number%20of%20Prefix%20Connected%20Groups/README.md
rating: 1401
source: 第 176 场双周赛 Q2
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3839.Number%20of%20Prefix%20Connected%20Groups/README_EN.md
rating: 1401
source: Biweekly Contest 176 Q2
---

<!-- problem:start -->
Expand Down
2 changes: 2 additions & 0 deletions solution/3800-3899/3840.House Robber V/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3840.House%20Robber%20V/README.md
rating: 1618
source: 第 176 场双周赛 Q3
---

<!-- problem:start -->
Expand Down
2 changes: 2 additions & 0 deletions solution/3800-3899/3840.House Robber V/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3840.House%20Robber%20V/README_EN.md
rating: 1618
source: Biweekly Contest 176 Q3
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3841.Palindromic%20Path%20Queries%20in%20a%20Tree/README.md
rating: 2384
source: 第 176 场双周赛 Q4
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3841.Palindromic%20Path%20Queries%20in%20a%20Tree/README_EN.md
rating: 2384
source: Biweekly Contest 176 Q4
---

<!-- problem:start -->
Expand Down
2 changes: 2 additions & 0 deletions solution/3800-3899/3842.Toggle Light Bulbs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3842.Toggle%20Light%20Bulbs/README.md
rating: 1160
source: 第 489 场周赛 Q1
---

<!-- problem:start -->
Expand Down
2 changes: 2 additions & 0 deletions solution/3800-3899/3842.Toggle Light Bulbs/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3842.Toggle%20Light%20Bulbs/README_EN.md
rating: 1160
source: Weekly Contest 489 Q1
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3843.First%20Element%20with%20Unique%20Frequency/README.md
rating: 1347
source: 第 489 场周赛 Q2
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3843.First%20Element%20with%20Unique%20Frequency/README_EN.md
rating: 1347
source: Weekly Contest 489 Q2
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3844.Longest%20Almost-Palindromic%20Substring/README.md
rating: 1989
source: 第 489 场周赛 Q3
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3844.Longest%20Almost-Palindromic%20Substring/README_EN.md
rating: 1989
source: Weekly Contest 489 Q3
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3845.Maximum%20Subarray%20XOR%20with%20Bounded%20Range/README.md
rating: 2347
source: 第 489 场周赛 Q4
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3800-3899/3845.Maximum%20Subarray%20XOR%20with%20Bounded%20Range/README_EN.md
rating: 2347
source: Weekly Contest 489 Q4
---

<!-- problem:start -->
Expand Down
Loading