Skip to content

Commit 1ee7e24

Browse files
authored
Merge pull request #1 from algorithm004-01/master
fetch from base
2 parents 3d456c5 + a09ba32 commit 1ee7e24

162 files changed

Lines changed: 1946 additions & 42 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Utils/.idea/Utils.iml‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Utils/.idea/misc.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Utils/.idea/modules.xml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Utils/.idea/vcs.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Utils/.idea/workspace.xml‎

Lines changed: 141 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Utils/git_quick_guide.md‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Environment Setup
2+
-----------------
3+
4+
### Git Download
5+
```
6+
Download Git according to Windows, Linux, Mac
7+
```
8+
9+
### Git global setup
10+
11+
```
12+
git config --global user.name "Your Name"
13+
git config --global user.email "youremail@xxx"
14+
```
15+
16+
### Add public key
17+
18+
* Add your public key
19+
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.
20+
21+
22+
Workflow with git
23+
-----------------
24+
25+
26+
### Prepare
27+
28+
* Open (https://github.com/algorithm004-01/algorithm004-01) in your browser, and click "Fork", choose your own namespace.
29+
30+
* Clone repo:
31+
32+
```
33+
git clone https://github.com/your_namespace/algorithm004-01.git
34+
or
35+
git clone git@github.com:your_namespace/algorithm004-01.git
36+
```
37+
38+
### Before developing a new homework
39+
40+
1. Choose the base branch on group fork
41+
42+
```
43+
git checkout master
44+
```
45+
2. Write your own code
46+
47+
48+
### After developing
49+
50+
1. Commit your changes in local repo.
51+
52+
```
53+
git add /path/to/files/you/changed
54+
git commit -m 'XXX submit xx homework code'
55+
```
56+
57+
58+
### Merge your changes to `algorithm004-01/algorithm004-01`
59+
60+
1. Push local commits to `your_namespace/algorithm004-01:mastr` in GitHub:
61+
62+
```
63+
git push origin master
64+
```
65+
66+
2. Create pull request from XXX to `algorithm004-01/algorithm004-01:master`
67+
![step1](https://github.com/honeyaya/algorithm004-01/blob/master/Utils/pr1.png)
68+
![step2](https://github.com/honeyaya/algorithm004-01/blob/master/Utils/pr2.png)
69+
70+
71+
72+
73+
Appendix
74+
--------
75+
76+
More Git Tutorial:
77+
- https://www.liaoxuefeng.com/wiki/896043488029600
78+
- 极客时间的git课程
79+

‎Utils/pr1.png‎

43.1 KB
Loading

‎Utils/pr2.png‎

47.2 KB
Loading
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// package io.github.shniu.arts.training.week01;
2+
3+
// https://leetcode-cn.com/problems/container-with-most-water/
4+
public class LeetCode_11_716 {
5+
6+
// 1. 暴力法, 时间复杂度高,O(n^2)
7+
public int maxArea1(int[] height) {
8+
int maxarea = 0;
9+
10+
for (int i = 0; i < height.length - 1; i++) {
11+
for (int j = i + 1; j < height.length; j++) {
12+
int minHeight = Math.min(height[i], height[j]);
13+
maxarea = Math.max(maxarea, minHeight * (j - i));
14+
}
15+
}
16+
17+
return maxarea;
18+
}
19+
20+
// 2. 双指针法
21+
// 2.1 写法
22+
public int maxArea21(int[] height) {
23+
int maxarea = 0;
24+
25+
for (int left = 0, right = height.length - 1; left < right;) {
26+
int minHeight = Math.min(height[left], height[right]);
27+
maxarea = Math.max(maxarea, minHeight * (right - left));
28+
// 看一下谁短就谁往里收缩一步
29+
if (height[left] < height[right]) {
30+
left++;
31+
} else {
32+
right--;
33+
}
34+
}
35+
36+
return maxarea;
37+
}
38+
39+
// 2.2 2.1写法的改进版
40+
public int maxArea22(int[] height) {
41+
int maxarea = 0;
42+
43+
for (int left = 0, right = height.length - 1; left < right;) {
44+
int minHeight = height[left] < height[right] ? height[left++] : height[right--];
45+
// 注意这里要+1
46+
maxarea = Math.max(maxarea, minHeight * (right - left + 1));
47+
}
48+
49+
return maxarea;
50+
}
51+
52+
// 2.3 更高效的写法
53+
public int maxArea23(int[] height) {
54+
int maxarea = 0;
55+
56+
for (int left = 0, right = height.length - 1; left < right;) {
57+
int minHeight = Math.min(height[left], height[right]);
58+
maxarea = Math.max(maxarea, minHeight * (right - left));
59+
60+
// 减少无用的面积计算次数,排除掉不需要计算的情况
61+
while (height[left] <= minHeight && left < right) left++;
62+
while (height[right] <= minHeight && left < right) right--;
63+
}
64+
65+
return maxarea;
66+
}
67+
}
68+

0 commit comments

Comments
 (0)