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
8 changes: 4 additions & 4 deletions solution/1000-1099/1032.Stream of Characters/README.md
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
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
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
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
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
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
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
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
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