Merge branch 'youngyangyang04:master' into master

This commit is contained in:
Frankheartusf
2022-05-04 23:09:30 +08:00
committed by GitHub
4 changed files with 90 additions and 4 deletions

View File

@ -531,7 +531,8 @@
如果是已工作,备注:姓名-城市-岗位-组队刷题。如果学生,备注:姓名-学校-年级-组队刷题。**备注没有自我介绍不通过哦** 如果是已工作,备注:姓名-城市-岗位-组队刷题。如果学生,备注:姓名-学校-年级-组队刷题。**备注没有自我介绍不通过哦**
<div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/20220426233122.png" data-img="1" width="200" height="200"></img></div>
<div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/第二企业刷题活码.png" data-img="1" width="200" height="200"></img></div>
@ -543,6 +544,7 @@
**来看看就知道了,你会发现相见恨晚!** **来看看就知道了,你会发现相见恨晚!**
<a name="公众号"></a> <a name="公众号"></a>
<div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/20211026122841.png" data-img="1" width="650" height="500"></img></div> <div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/20211026122841.png" data-img="1" width="650" height="500"></img></div>

View File

@ -281,9 +281,7 @@ func removeElement(_ nums: inout [Int], _ val: Int) -> Int {
for fastIndex in 0..<nums.count { for fastIndex in 0..<nums.count {
if val != nums[fastIndex] { if val != nums[fastIndex] {
if slowIndex != fastIndex {
nums[slowIndex] = nums[fastIndex] nums[slowIndex] = nums[fastIndex]
}
slowIndex += 1 slowIndex += 1
} }
} }

View File

@ -311,7 +311,36 @@ class Solution:
``` ```
Go: Go:
> 贪心法:
```Go
func maxProfit(prices []int) int {
low := math.MaxInt32
rlt := 0
for i := range prices{
low = min(low, prices[i])
rlt = max(rlt, prices[i]-low)
}
return rlt
}
func min(a, b int) int {
if a < b{
return a
}
return b
}
func max(a, b int) int {
if a > b{
return a
}
return b
}
```
> 动态规划:版本一
```Go ```Go
func maxProfit(prices []int) int { func maxProfit(prices []int) int {
length:=len(prices) length:=len(prices)
@ -338,6 +367,29 @@ func max(a,b int)int {
} }
``` ```
> 动态规划:版本二
```Go
func maxProfit(prices []int) int {
dp := [2][2]int{}
dp[0][0] = -prices[0]
dp[0][1] = 0
for i := 1; i < len(prices); i++{
dp[i%2][0] = max(dp[(i-1)%2][0], -prices[i])
dp[i%2][1] = max(dp[(i-1)%2][1], dp[(i-1)%2][0]+prices[i])
}
return dp[(len(prices)-1)%2][1]
}
func max(a, b int) int {
if a > b{
return a
}
return b
}
```
JavaScript: JavaScript:
> 动态规划 > 动态规划

View File

@ -252,5 +252,39 @@ var lemonadeChange = function(bills) {
``` ```
### TypeScript
```typescript
function lemonadeChange(bills: number[]): boolean {
let five: number = 0,
ten: number = 0;
for (let bill of bills) {
switch (bill) {
case 5:
five++;
break;
case 10:
if (five < 1) return false;
five--;
ten++
break;
case 20:
if (ten > 0 && five > 0) {
five--;
ten--;
} else if (five > 2) {
five -= 3;
} else {
return false;
}
break;
}
}
return true;
};
```
----------------------- -----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div> <div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>