Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] main from doocs:main #200

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
pull merged 2 commits into FairyWorld:main from doocs:main
Mar 25, 2023
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
8 changes: 4 additions & 4 deletions solution/1000-1099/1032.Stream of Characters/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Trie {

public boolean query(StringBuilder s) {
Trie node = this;
for (int i = s.length() - 1, j = 0; i >= 0 && j < 201; --i, ++j) {
for (int i = s.length() - 1; i >= 0; --i) {
int idx = s.charAt(i) - 'a';
if (node.children[idx] == null) {
return false;
Expand Down Expand Up @@ -211,7 +211,7 @@ public:

bool search(string& w) {
Trie* node = this;
for (int i = w.size() - 1, j = 0; ~i && j < 201; --i, ++j) {
for (int i = w.size() - 1; ~i; --i) {
int idx = w[i] - 'a';
if (!node->children[idx]) {
return false;
Expand All @@ -231,7 +231,7 @@ public:
string s;

StreamChecker(vector<string>& words) {
for (auto& w : words) {
for (auto&& w : words) {
trie->insert(w);
}
}
Expand Down Expand Up @@ -275,7 +275,7 @@ func (this *Trie) Insert(word string) {

func (this *Trie) Search(word []byte) bool {
node := this
for i, j := len(word)-1, 0; i >= 0 && j < 201; i, j = i-1, j+1 {
for i:= len(word) - 1; i >= 0; i-- {
idx := word[i] - 'a'
if node.children[idx] == nil {
return false
Expand Down
8 changes: 4 additions & 4 deletions solution/1000-1099/1032.Stream of Characters/README_EN.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Trie {

public boolean query(StringBuilder s) {
Trie node = this;
for (int i = s.length() - 1, j = 0; i >= 0 && j < 201; --i, ++j) {
for (int i = s.length() - 1; i >= 0; --i) {
int idx = s.charAt(i) - 'a';
if (node.children[idx] == null) {
return false;
Expand Down Expand Up @@ -188,7 +188,7 @@ public:

bool search(string& w) {
Trie* node = this;
for (int i = w.size() - 1, j = 0; ~i && j < 201; --i, ++j) {
for (int i = w.size() - 1; ~i; --i) {
int idx = w[i] - 'a';
if (!node->children[idx]) {
return false;
Expand All @@ -208,7 +208,7 @@ public:
string s;

StreamChecker(vector<string>& words) {
for (auto& w : words) {
for (auto&& w : words) {
trie->insert(w);
}
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func (this *Trie) Insert(word string) {

func (this *Trie) Search(word []byte) bool {
node := this
for i, j := len(word)-1, 0; i >= 0 && j < 201; i, j = i-1, j+1 {
for i:= len(word) - 1; i >= 0; i-- {
idx := word[i] - 'a'
if node.children[idx] == nil {
return false
Expand Down
4 changes: 2 additions & 2 deletions solution/1000-1099/1032.Stream of Characters/Solution.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Trie {

bool search(string& w) {
Trie* node = this;
for (int i = w.size() - 1, j = 0; ~i && j < 201; --i, ++j) {
for (int i = w.size() - 1; ~i; --i) {
int idx = w[i] - 'a';
if (!node->children[idx]) {
return false;
Expand All @@ -42,7 +42,7 @@ class StreamChecker {
string s;

StreamChecker(vector<string>& words) {
for (auto& w : words) {
for (auto&& w : words) {
trie->insert(w);
}
}
Expand Down
2 changes: 1 addition & 1 deletion solution/1000-1099/1032.Stream of Characters/Solution.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (this *Trie) Insert(word string) {

func (this *Trie) Search(word []byte) bool {
node := this
for i, j := len(word)-1, 0; i >= 0 && j < 201; i, j = i-1, j+1 {
for i:= len(word) - 1; i >= 0; i-- {
idx := word[i] - 'a'
if node.children[idx] == nil {
return false
Expand Down
2 changes: 1 addition & 1 deletion solution/1000-1099/1032.Stream of Characters/Solution.java
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void insert(String w) {

public boolean query(StringBuilder s) {
Trie node = this;
for (int i = s.length() - 1, j = 0; i >= 0 && j < 201; --i, ++j) {
for (int i = s.length() - 1; i >= 0; --i) {
int idx = s.charAt(i) - 'a';
if (node.children[idx] == null) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions solution/1000-1099/1032.Stream of Characters/Solution.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def search(self, w: List[str]) -> bool:


class StreamChecker:

def __init__(self, words: List[str]):
self.trie = Trie()
self.cs = []
Expand All @@ -35,7 +34,8 @@ def __init__(self, words: List[str]):

def query(self, letter: str) -> bool:
self.cs.append(letter)
return self.trie.search(self.cs[-self.limit:])
return self.trie.search(self.cs[-self.limit :])


# Your StreamChecker object will be instantiated and called as such:
# obj = StreamChecker(words)
Expand Down
36 changes: 36 additions & 0 deletions solution/1000-1099/1034.Coloring A Border/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,42 @@ func colorBorder(grid [][]int, row int, col int, color int) [][]int {
}
```

### **TypeScript**

```ts
function colorBorder(
grid: number[][],
row: number,
col: number,
color: number,
): number[][] {
const m = grid.length;
const n = grid[0].length;
const vis = new Array(m).fill(0).map(() => new Array(n).fill(false));
const dirs = [-1, 0, 1, 0, -1];
const dfs = (i: number, j: number, c: number) => {
vis[i][j] = true;
for (let k = 0; k < 4; ++k) {
const x = i + dirs[k];
const y = j + dirs[k + 1];
if (x >= 0 && x < m && y >= 0 && y < n) {
if (!vis[x][y]) {
if (grid[x][y] == c) {
dfs(x, y, c);
} else {
grid[i][j] = color;
}
}
} else {
grid[i][j] = color;
}
}
};
dfs(row, col, grid[row][col]);
return grid;
}
```

### **...**

```
Expand Down
36 changes: 36 additions & 0 deletions solution/1000-1099/1034.Coloring A Border/README_EN.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,42 @@ func colorBorder(grid [][]int, row int, col int, color int) [][]int {
}
```

### **TypeScript**

```ts
function colorBorder(
grid: number[][],
row: number,
col: number,
color: number,
): number[][] {
const m = grid.length;
const n = grid[0].length;
const vis = new Array(m).fill(0).map(() => new Array(n).fill(false));
const dirs = [-1, 0, 1, 0, -1];
const dfs = (i: number, j: number, c: number) => {
vis[i][j] = true;
for (let k = 0; k < 4; ++k) {
const x = i + dirs[k];
const y = j + dirs[k + 1];
if (x >= 0 && x < m && y >= 0 && y < n) {
if (!vis[x][y]) {
if (grid[x][y] == c) {
dfs(x, y, c);
} else {
grid[i][j] = color;
}
}
} else {
grid[i][j] = color;
}
}
};
dfs(row, col, grid[row][col]);
return grid;
}
```

### **...**

```
Expand Down
31 changes: 31 additions & 0 deletions solution/1000-1099/1034.Coloring A Border/Solution.ts
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function colorBorder(
grid: number[][],
row: number,
col: number,
color: number,
): number[][] {
const m = grid.length;
const n = grid[0].length;
const vis = new Array(m).fill(0).map(() => new Array(n).fill(false));
const dirs = [-1, 0, 1, 0, -1];
const dfs = (i: number, j: number, c: number) => {
vis[i][j] = true;
for (let k = 0; k < 4; ++k) {
const x = i + dirs[k];
const y = j + dirs[k + 1];
if (x >= 0 && x < m && y >= 0 && y < n) {
if (!vis[x][y]) {
if (grid[x][y] == c) {
dfs(x, y, c);
} else {
grid[i][j] = color;
}
}
} else {
grid[i][j] = color;
}
}
};
dfs(row, col, grid[row][col]);
return grid;
}
Loading

AltStyle によって変換されたページ (->オリジナル) /