Skip to content

Commit

Permalink
Merge pull request #1 from algorithm004-01/master
Browse files Browse the repository at this point in the history
更新第一周内容
  • Loading branch information
laxlyt committed Oct 15, 2019
2 parents 724952d + a09ba32 commit b900538
Show file tree
Hide file tree
Showing 164 changed files with 1,951 additions and 41 deletions.
11 changes: 11 additions & 0 deletions Utils/.idea/Utils.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Utils/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Utils/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Utils/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 141 additions & 0 deletions Utils/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions Utils/git_quick_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Environment Setup
-----------------

### Git Download
```
Download Git according to Windows, Linux, Mac
```

### Git global setup

```
git config --global user.name "Your Name"
git config --global user.email "youremail@xxx"
```

### Add public key

* Add your public key
Note: [Here](https://help.github.com/enterprise/2.15/user/articles/connecting-to-github-with-ssh) is the document about how to add the ssh key.


Workflow with git
-----------------


### Prepare

* Open (https://github.com/algorithm004-01/algorithm004-01) in your browser, and click "Fork", choose your own namespace.

* Clone repo:

```
git clone https://github.com/your_namespace/algorithm004-01.git
or
git clone git@github.com:your_namespace/algorithm004-01.git
```

### Before developing a new homework

1. Choose the base branch on group fork

```
git checkout master
```
2. Write your own code


### After developing

1. Commit your changes in local repo.

```
git add /path/to/files/you/changed
git commit -m 'XXX submit xx homework code'
```


### Merge your changes to `algorithm004-01/algorithm004-01`

1. Push local commits to `your_namespace/algorithm004-01:mastr` in GitHub:

```
git push origin master
```

2. Create pull request from XXX to `algorithm004-01/algorithm004-01:master`
![step1](https://github.com/honeyaya/algorithm004-01/blob/master/Utils/pr1.png)
![step2](https://github.com/honeyaya/algorithm004-01/blob/master/Utils/pr2.png)




Appendix
--------

More Git Tutorial:
- https://www.liaoxuefeng.com/wiki/896043488029600
- 极客时间的git课程

Binary file added Utils/pr1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Utils/pr2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions Week 01/id_716/LeetCode_11_716.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// package io.github.shniu.arts.training.week01;

// https://leetcode-cn.com/problems/container-with-most-water/
public class LeetCode_11_716 {

// 1. 暴力法, 时间复杂度高,O(n^2)
public int maxArea1(int[] height) {
int maxarea = 0;

for (int i = 0; i < height.length - 1; i++) {
for (int j = i + 1; j < height.length; j++) {
int minHeight = Math.min(height[i], height[j]);
maxarea = Math.max(maxarea, minHeight * (j - i));
}
}

return maxarea;
}

// 2. 双指针法
// 2.1 写法
public int maxArea21(int[] height) {
int maxarea = 0;

for (int left = 0, right = height.length - 1; left < right;) {
int minHeight = Math.min(height[left], height[right]);
maxarea = Math.max(maxarea, minHeight * (right - left));
// 看一下谁短就谁往里收缩一步
if (height[left] < height[right]) {
left++;
} else {
right--;
}
}

return maxarea;
}

// 2.2 2.1写法的改进版
public int maxArea22(int[] height) {
int maxarea = 0;

for (int left = 0, right = height.length - 1; left < right;) {
int minHeight = height[left] < height[right] ? height[left++] : height[right--];
// 注意这里要+1
maxarea = Math.max(maxarea, minHeight * (right - left + 1));
}

return maxarea;
}

// 2.3 更高效的写法
public int maxArea23(int[] height) {
int maxarea = 0;

for (int left = 0, right = height.length - 1; left < right;) {
int minHeight = Math.min(height[left], height[right]);
maxarea = Math.max(maxarea, minHeight * (right - left));

// 减少无用的面积计算次数,排除掉不需要计算的情况
while (height[left] <= minHeight && left < right) left++;
while (height[right] <= minHeight && left < right) right--;
}

return maxarea;
}
}

Loading

0 comments on commit b900538

Please sign in to comment.