Skip to content

[pull] main from doocs:main #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 9, 2024
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
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use Node.js version 14 as the base image
FROM node:14

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json (if present) to the working directory
COPY package*.json ./

# Install npm dependencies
RUN npm install

# Copy all files from the current directory to the working directory in the container
COPY . .

# Expose port 80 to allow communication to/from the container
EXPOSE 80

# Specify the command to run the application
CMD ["npm", "start"]
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Solution {
func singleNonDuplicate(_ nums: [Int]) -> Int {
var left = 0
var right = nums.count - 1

while left < right {
let mid = (left + right) / 2
if nums[mid] != nums[mid ^ 1] {
Expand All @@ -167,7 +167,7 @@ class Solution {
left = mid + 1
}
}

return nums[left]
}
}
Expand Down
28 changes: 28 additions & 0 deletions solution/0000-0099/0052.N-Queens II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,34 @@ function totalNQueens(n: number): number {
}
```

#### JavaScript

```js
function totalNQueens(n) {
const cols = Array(10).fill(false);
const dg = Array(20).fill(false);
const udg = Array(20).fill(false);
let ans = 0;
const dfs = i => {
if (i === n) {
++ans;
return;
}
for (let j = 0; j < n; ++j) {
let [a, b] = [i + j, i - j + n];
if (cols[j] || dg[a] || udg[b]) {
continue;
}
cols[j] = dg[a] = udg[b] = true;
dfs(i + 1);
cols[j] = dg[a] = udg[b] = false;
}
};
dfs(0);
return ans;
}
```

#### C#

```cs
Expand Down
28 changes: 28 additions & 0 deletions solution/0000-0099/0052.N-Queens II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,34 @@ function totalNQueens(n: number): number {
}
```

#### JavaScript

```js
function totalNQueens(n) {
const cols = Array(10).fill(false);
const dg = Array(20).fill(false);
const udg = Array(20).fill(false);
let ans = 0;
const dfs = i => {
if (i === n) {
++ans;
return;
}
for (let j = 0; j < n; ++j) {
let [a, b] = [i + j, i - j + n];
if (cols[j] || dg[a] || udg[b]) {
continue;
}
cols[j] = dg[a] = udg[b] = true;
dfs(i + 1);
cols[j] = dg[a] = udg[b] = false;
}
};
dfs(0);
return ans;
}
```

#### C#

```cs
Expand Down
23 changes: 23 additions & 0 deletions solution/0000-0099/0052.N-Queens II/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function totalNQueens(n) {
const cols = Array(10).fill(false);
const dg = Array(20).fill(false);
const udg = Array(20).fill(false);
let ans = 0;
const dfs = i => {
if (i === n) {
++ans;
return;
}
for (let j = 0; j < n; ++j) {
let [a, b] = [i + j, i - j + n];
if (cols[j] || dg[a] || udg[b]) {
continue;
}
cols[j] = dg[a] = udg[b] = true;
dfs(i + 1);
cols[j] = dg[a] = udg[b] = false;
}
};
dfs(0);
return ans;
}
36 changes: 36 additions & 0 deletions solution/0000-0099/0079.Word Search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,42 @@ function exist(board: string[][], word: string): boolean {
}
```

#### JavaScript

```js
function exist(board, word) {
const [m, n] = [board.length, board[0].length];
const dirs = [-1, 0, 1, 0, -1];
const dfs = (i, j, k) => {
if (k === word.length - 1) {
return board[i][j] === word[k];
}
if (board[i][j] !== word[k]) {
return false;
}
const c = board[i][j];
board[i][j] = '0';
for (let u = 0; u < 4; ++u) {
const [x, y] = [i + dirs[u], j + dirs[u + 1]];
const ok = x >= 0 && x < m && y >= 0 && y < n;
if (ok && board[x][y] !== '0' && dfs(x, y, k + 1)) {
return true;
}
}
board[i][j] = c;
return false;
};
for (let i = 0; i < m; ++i) {
for (let j = 0; j < n; ++j) {
if (dfs(i, j, 0)) {
return true;
}
}
}
return false;
}
```

#### Rust

```rust
Expand Down
36 changes: 36 additions & 0 deletions solution/0000-0099/0079.Word Search/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,42 @@ function exist(board: string[][], word: string): boolean {
}
```

#### JavaScript

```js
function exist(board, word) {
const [m, n] = [board.length, board[0].length];
const dirs = [-1, 0, 1, 0, -1];
const dfs = (i, j, k) => {
if (k === word.length - 1) {
return board[i][j] === word[k];
}
if (board[i][j] !== word[k]) {
return false;
}
const c = board[i][j];
board[i][j] = '0';
for (let u = 0; u < 4; ++u) {
const [x, y] = [i + dirs[u], j + dirs[u + 1]];
const ok = x >= 0 && x < m && y >= 0 && y < n;
if (ok && board[x][y] !== '0' && dfs(x, y, k + 1)) {
return true;
}
}
board[i][j] = c;
return false;
};
for (let i = 0; i < m; ++i) {
for (let j = 0; j < n; ++j) {
if (dfs(i, j, 0)) {
return true;
}
}
}
return false;
}
```

#### Rust

```rust
Expand Down
31 changes: 31 additions & 0 deletions solution/0000-0099/0079.Word Search/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function exist(board, word) {
const [m, n] = [board.length, board[0].length];
const dirs = [-1, 0, 1, 0, -1];
const dfs = (i, j, k) => {
if (k === word.length - 1) {
return board[i][j] === word[k];
}
if (board[i][j] !== word[k]) {
return false;
}
const c = board[i][j];
board[i][j] = '0';
for (let u = 0; u < 4; ++u) {
const [x, y] = [i + dirs[u], j + dirs[u + 1]];
const ok = x >= 0 && x < m && y >= 0 && y < n;
if (ok && board[x][y] !== '0' && dfs(x, y, k + 1)) {
return true;
}
}
board[i][j] = c;
return false;
};
for (let i = 0; i < m; ++i) {
for (let j = 0; j < n; ++j) {
if (dfs(i, j, 0)) {
return true;
}
}
}
return false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ impl Solution {
if n == 1 {
return 1;
}
let mut ans = (k + Solution::find_the_winner(n - 1, k)) % n;
return if ans == 0 { n } else { ans };
let mut ans = (k + Solution::find_the_winner(n - 1, k)) % n;
return if ans == 0 { n } else { ans };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3205.Maximum%20Array%20Hopping%20Score%20I/README.md
tags:
- 栈
- 数组
- 动态规划
- 单调栈
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3205.Maximum%20Array%20Hopping%20Score%20I/README_EN.md
tags:
- Stack
- Array
- Dynamic Programming
- Monotonic Stack
---

<!-- problem:start -->
Expand Down
3 changes: 3 additions & 0 deletions solution/3200-3299/3206.Alternating Groups I/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3206.Alternating%20Groups%20I/README.md
tags:
- 数组
- 滑动窗口
---

<!-- problem:start -->
Expand Down
3 changes: 3 additions & 0 deletions solution/3200-3299/3206.Alternating Groups I/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3206.Alternating%20Groups%20I/README_EN.md
tags:
- Array
- Sliding Window
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3207.Maximum%20Points%20After%20Enemy%20Battles/README.md
tags:
- 贪心
- 数组
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3207.Maximum%20Points%20After%20Enemy%20Battles/README_EN.md
tags:
- Greedy
- Array
---

<!-- problem:start -->
Expand Down
3 changes: 3 additions & 0 deletions solution/3200-3299/3208.Alternating Groups II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3208.Alternating%20Groups%20II/README.md
tags:
- 数组
- 滑动窗口
---

<!-- problem:start -->
Expand Down
3 changes: 3 additions & 0 deletions solution/3200-3299/3208.Alternating Groups II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3208.Alternating%20Groups%20II/README_EN.md
tags:
- Array
- Sliding Window
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3209.Number%20of%20Subarrays%20With%20AND%20Value%20of%20K/README.md
tags:
- 位运算
- 线段树
- 数组
- 二分查找
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3209.Number%20of%20Subarrays%20With%20AND%20Value%20of%20K/README_EN.md
tags:
- Bit Manipulation
- Segment Tree
- Array
- Binary Search
---

<!-- problem:start -->
Expand Down
2 changes: 2 additions & 0 deletions solution/3200-3299/3210.Find the Encrypted String/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/3200-3299/3210.Find%20the%20Encrypted%20String/README.md
tags:
- 字符串
---

<!-- problem:start -->
Expand Down
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/3200-3299/3210.Find%20the%20Encrypted%20String/README_EN.md
tags:
- String
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3211.Generate%20Binary%20Strings%20Without%20Adjacent%20Zeros/README.md
tags:
- 位运算
- 递归
- 字符串
---

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