-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from algorithm004-01/master
更新第一周内容
- Loading branch information
Showing
164 changed files
with
1,951 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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课程 | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
Oops, something went wrong.