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

Commit c1daefd

Browse files
committed
feat: update solutions to lc problems: No.0240,2047
No.0240.Search 2D Matrix II No.2047.Number of Valid Words in a Sentence
1 parent fa64fa3 commit c1daefd

File tree

7 files changed

+94
-30
lines changed

7 files changed

+94
-30
lines changed

‎solution/0200-0299/0240.Search a 2D Matrix II/README.md‎

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,11 @@ public:
122122
bool searchMatrix(vector<vector<int>>& matrix, int target) {
123123
int m = matrix.size(), n = matrix[0].size();
124124
int i = m - 1, j = 0;
125-
while (i >= 0 && j < n) {
126-
if (matrix[i][j] == target) {
127-
return true;
128-
}
129-
if (matrix[i][j] > target) {
130-
--i;
131-
} else {
132-
++j;
133-
}
125+
while (i >= 0 && j < n)
126+
{
127+
if (matrix[i][j] == target) return true;
128+
if (matrix[i][j] > target) --i;
129+
else ++j;
134130
}
135131
return false;
136132
}
@@ -157,6 +153,33 @@ func searchMatrix(matrix [][]int, target int) bool {
157153
}
158154
```
159155

156+
### **C#**
157+
158+
```cs
159+
public class Solution {
160+
public bool SearchMatrix(int[][] matrix, int target) {
161+
int m = matrix.Length, n = matrix[0].Length;
162+
int i = m - 1, j = 0;
163+
while (i >= 0 && j < n)
164+
{
165+
if (matrix[i][j] == target)
166+
{
167+
return true;
168+
}
169+
if (matrix[i][j] > target)
170+
{
171+
--i;
172+
}
173+
else
174+
{
175+
++j;
176+
}
177+
}
178+
return false;
179+
}
180+
}
181+
```
182+
160183
### **...**
161184

162185
```

‎solution/0200-0299/0240.Search a 2D Matrix II/README_EN.md‎

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,11 @@ public:
110110
bool searchMatrix(vector<vector<int>>& matrix, int target) {
111111
int m = matrix.size(), n = matrix[0].size();
112112
int i = m - 1, j = 0;
113-
while (i >= 0 && j < n) {
114-
if (matrix[i][j] == target) {
115-
return true;
116-
}
117-
if (matrix[i][j] > target) {
118-
--i;
119-
} else {
120-
++j;
121-
}
113+
while (i >= 0 && j < n)
114+
{
115+
if (matrix[i][j] == target) return true;
116+
if (matrix[i][j] > target) --i;
117+
else ++j;
122118
}
123119
return false;
124120
}
@@ -145,6 +141,33 @@ func searchMatrix(matrix [][]int, target int) bool {
145141
}
146142
```
147143

144+
### **C#**
145+
146+
```cs
147+
public class Solution {
148+
public bool SearchMatrix(int[][] matrix, int target) {
149+
int m = matrix.Length, n = matrix[0].Length;
150+
int i = m - 1, j = 0;
151+
while (i >= 0 && j < n)
152+
{
153+
if (matrix[i][j] == target)
154+
{
155+
return true;
156+
}
157+
if (matrix[i][j] > target)
158+
{
159+
--i;
160+
}
161+
else
162+
{
163+
++j;
164+
}
165+
}
166+
return false;
167+
}
168+
}
169+
```
170+
148171
### **...**
149172

150173
```

‎solution/0200-0299/0240.Search a 2D Matrix II/Solution.cpp‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ class Solution {
33
bool searchMatrix(vector<vector<int>>& matrix, int target) {
44
int m = matrix.size(), n = matrix[0].size();
55
int i = m - 1, j = 0;
6-
while (i >= 0 && j < n) {
7-
if (matrix[i][j] == target) {
8-
return true;
9-
}
10-
if (matrix[i][j] > target) {
11-
--i;
12-
} else {
13-
++j;
14-
}
6+
while (i >= 0 && j < n)
7+
{
8+
if (matrix[i][j] == target) return true;
9+
if (matrix[i][j] > target) --i;
10+
else ++j;
1511
}
1612
return false;
1713
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Solution {
2+
public bool SearchMatrix(int[][] matrix, int target) {
3+
int m = matrix.Length, n = matrix[0].Length;
4+
int i = m - 1, j = 0;
5+
while (i >= 0 && j < n)
6+
{
7+
if (matrix[i][j] == target)
8+
{
9+
return true;
10+
}
11+
if (matrix[i][j] > target)
12+
{
13+
--i;
14+
}
15+
else
16+
{
17+
++j;
18+
}
19+
}
20+
return false;
21+
}
22+
}

‎solution/2000-2099/2047.Number of Valid Words in a Sentence/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function countValidWords(sentence: string): number {
9292
let words = sentence.trim().split(/\s+/);
9393
let ans = 0;
9494
for (let word of words) {
95-
if(isValied(word)) {
95+
if(isValied(word)) {
9696
ans++;
9797
}
9898
}

‎solution/2000-2099/2047.Number of Valid Words in a Sentence/README_EN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function countValidWords(sentence: string): number {
8686
let words = sentence.trim().split(/\s+/);
8787
let ans = 0;
8888
for (let word of words) {
89-
if(isValied(word)) {
89+
if(isValied(word)) {
9090
ans++;
9191
}
9292
}

‎solution/2000-2099/2047.Number of Valid Words in a Sentence/Solution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function countValidWords(sentence: string): number {
33
let words = sentence.trim().split(/\s+/);
44
let ans = 0;
55
for (let word of words) {
6-
if(isValied(word)) {
6+
if(isValied(word)) {
77
ans++;
88
}
99
}

0 commit comments

Comments
(0)

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