Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/azl397985856/leetcode
Browse files Browse the repository at this point in the history
  • Loading branch information
lucifer committed Sep 30, 2020
2 parents d64a7bd + 43060b1 commit 4d04939
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
41 changes: 40 additions & 1 deletion problems/200.number-of-islands.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,46 @@ Output: 3

## 代码

* 语言支持:JS, python3,Java
* 语言支持:C++, Java, JS, python3


C++ Code:

```c++
class Solution {
public:
int numIslands(vector<vector<char>>& grid) {
int res = 0;
for(int i=0;i<grid.size();i++)
{
for(int j=0;j<grid[0].size();j++)
{
if(grid[i][j] == '1')
{
dfs(grid, i, j);
res += 1;
}
}
}
return res;

}
void dfs(vector<vector<char>>& grid, int i, int j)
{
// edge
if(i<0 || i>= grid.size() || j<0 || j>= grid[0].size() || grid[i][j] != '1')
{
return;
}
grid[i][j] = '0';
dfs(grid, i+1, j);
dfs(grid, i-1, j);
dfs(grid, i, j+1);
dfs(grid, i, j-1);
}
};

```
Java Code:
Expand Down
31 changes: 29 additions & 2 deletions problems/88.merge-sorted-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function merge(nums1, nums2) {

## 代码

代码支持:Python3 C++ JavaScript
代码支持:Python3, C++, Java, JavaScript

JavaSCript Code:

Expand Down Expand Up @@ -173,7 +173,34 @@ public:
};
```

Python Code
Java Code:

```java
class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
int i=m-1, j=n-1, k=m+n-1;
// 合并
while(i>=0 && j>=0)
{
if(nums1[i] > nums2[j])
{
nums1[k--] = nums1[i--];
}
else
{
nums1[k--] = nums2[j--];
}
}
// 合并剩余的nums2
while(j>=0)
{
nums1[k--] = nums2[j--];
}
}
}
```

Python Code:

```python
class Solution:
Expand Down

0 comments on commit 4d04939

Please sign in to comment.