Algorithm
lc121_买卖股票的最佳时机
思路:
这个是最大最小值之间的绝对值的进化版,需要通过遍历维护当前最小值和当下卖出的收益来维护贪心收益。
一次AC了,和题解最优法是一样的。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
class Solution {
public:
int maxProfit(vector<int>& prices) {
int sz = prices.size();
assert(sz >= 1);
int pre_min = prices[0];
int ans = 0;
for (int i = 1; i < sz; i++) {
if (prices[i] > pre_min) {
ans = max(ans, prices[i] - pre_min);
continue;
}
pre_min = min(pre_min, prices[i]);
}
return ans;
}
};
|
Review
【TED演讲】奥运冠军如何克服恐惧的心态
直面恐惧,推动世界的改变。
这里虽然可能跟社会环境有很大的关系,但是尽力而为,为而不争,问心无愧总是好的。
如果能成功,将对世界带来好处,让未来同样处境的人不再恐惧。
Tips
Musl libc_为什么需要另一个libc
Share_git_submodule提交内容实操
因为子库和母库保持了独立commit,所以提交完子库之后,在母库会发现提醒说子库更新了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
❯ git st
On branch rocksdb
Your branch is up to date with 'origin/rocksdb'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: third-party/rocksdb (new commits)
Submodules changed but not updated:
* third-party/rocksdb b168576...ec67e87 (1):
> [ADD] install-static some change
Untracked files:
(use "git add <file>..." to include in what will be committed)
compile_commands.json
no changes added to commit (use "git add" and/or "git commit -a")
❯ git add -u
❯ git st
On branch rocksdb
Your branch is up to date with 'origin/rocksdb'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: third-party/rocksdb
Submodule changes to be committed:
* third-party/rocksdb b168576...ec67e87 (1):
> [ADD] install-static some change
Untracked files:
(use "git add <file>..." to include in what will be committed)
compile_commands.json
❯ git cm -m "[ADD] rocksdb_install-static some change"
[rocksdb 221e94058] [ADD] rocksdb_install-static some change
1 file changed, 1 insertion(+), 1 deletion(-)
❯ git st
On branch rocksdb
Your branch is ahead of 'origin/rocksdb' by 1 commit.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
compile_commands.json
nothing added to commit but untracked files present (use "git add" to track)
❯ git push
Counting objects: 3, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 422 bytes | 422.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote:
remote: To create a merge request for rocksdb, visit:
remote: https://gitlab.XXX.xxx/XXX/XXX/-/merge_requests/new?merge_request%5Bsource_branch%5D=rocksdb
remote:
To gitlab.XXX.xyz:XXX/xxx.git
5a795e575..221e94058 rocksdb -> rocksdb
|
在这篇文章中得到了验证: Git中submodule的使用.