Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 26 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
21475ad
修正了其中一个错别字
languagege May 9, 2022
7519826
Update 0019.删除链表的倒数第N个节点.md
qingfengpiaoa May 10, 2022
c62d518
fix bug
FizzerYu May 10, 2022
d92aa2c
Add 0112.路径总和.md C语言解法
KingArthur0205 May 10, 2022
cc2c2ad
添加 0977.有序数组的平方.md Scala版本
wzqwtt May 11, 2022
842c042
添加(背包问题理论基础多重背包.md):增加typescript版本
xiaofei-2020 May 11, 2022
871d96a
添加 0209.长度最小的子数组.md Scala版本
wzqwtt May 11, 2022
cb2fea6
添加 0113.路径总和II C语言解法
KingArthur0205 May 11, 2022
c363e9d
添加(0198.打家劫舍.md):增加typescript版本
xiaofei-2020 May 11, 2022
2964855
添加(0213.打家劫舍II.md):增加typescript版本
xiaofei-2020 May 11, 2022
1e9bb56
Merge branch 'youngyangyang04:master' into master
KingArthur0205 May 14, 2022
5da6c06
添加 背包理论肌醇01背包 C语言版本
KingArthur0205 May 14, 2022
4defb3d
Merge branch 'master' of https://github.com/KingArthur0205/leetcode-m...
KingArthur0205 May 14, 2022
a20ac9d
Merge branch 'youngyangyang04:master' into master
KingArthur0205 May 15, 2022
aa22b80
添加 背包理论基础01-2.mc C语言版本
KingArthur0205 May 15, 2022
d15c4af
Merge branch 'master' of https://github.com/KingArthur0205/leetcode-m...
KingArthur0205 May 15, 2022
19abe18
添加 0416.分割等和子集.md C语言版本
KingArthur0205 May 15, 2022
4f94d8a
Merge pull request #1296 from languagege/master
youngyangyang04 May 27, 2022
b4a40a2
Merge pull request #1298 from qingfengpiaoa/master
youngyangyang04 May 27, 2022
5719c00
Merge pull request #1301 from FizzerYu/patch-1
youngyangyang04 May 27, 2022
45a8a6b
Merge branch 'master' into master
youngyangyang04 May 27, 2022
309643e
Merge pull request #1302 from KingArthur0205/master
youngyangyang04 May 27, 2022
7684a1c
Merge pull request #1304 from xiaofei-2020/dp27
youngyangyang04 May 27, 2022
f115be0
Merge pull request #1305 from ZongqinWang/patch01
youngyangyang04 May 27, 2022
bb32a41
Merge pull request #1306 from xiaofei-2020/dp29
youngyangyang04 May 27, 2022
0e3a1bc
Merge pull request #1307 from xiaofei-2020/dp30
youngyangyang04 May 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions problems/0209.长度最小的子数组.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,54 @@ class Solution {
}
}
```
Scala:

滑动窗口:
```scala
object Solution {
def minSubArrayLen(target: Int, nums: Array[Int]): Int = {
var result = Int.MaxValue // 返回结果,默认最大值
var left = 0 // 慢指针,当sum>=target,向右移动
var sum = 0 // 窗口值的总和
for (right <- 0 until nums.length) {
sum += nums(right)
while (sum >= target) {
result = math.min(result, right - left + 1) // 产生新结果
sum -= nums(left) // 左指针移动,窗口总和减去左指针的值
left += 1 // 左指针向右移动
}
}
// 相当于三元运算符,return关键字可以省略
if (result == Int.MaxValue) 0 else result
}
}
```

暴力解法:
```scala
object Solution {
def minSubArrayLen(target: Int, nums: Array[Int]): Int = {
import scala.util.control.Breaks
var res = Int.MaxValue
var subLength = 0
for (i <- 0 until nums.length) {
var sum = 0
Breaks.breakable(
for (j <- i until nums.length) {
sum += nums(j)
if (sum >= target) {
subLength = j - i + 1
res = math.min(subLength, res)
Breaks.break()
}
}
)
}
// 相当于三元运算符
if (res == Int.MaxValue) 0 else res
}
}
```

-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
36 changes: 35 additions & 1 deletion problems/0977.有序数组的平方.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,41 @@ class Solution {
}
}
```

Scala:

双指针:
```scala
object Solution {
def sortedSquares(nums: Array[Int]): Array[Int] = {
val res: Array[Int] = new Array[Int](nums.length)
var top = nums.length - 1
var i = 0
var j = nums.length - 1
while (i <= j) {
if (nums(i) * nums(i) <= nums(j) * nums(j)) {
// 当左侧平方小于等于右侧,res数组顶部放右侧的平方,并且top下移,j左移
res(top) = nums(j) * nums(j)
top -= 1
j -= 1
} else {
// 当左侧平方大于右侧,res数组顶部放左侧的平方,并且top下移,i右移
res(top) = nums(i) * nums(i)
top -= 1
i += 1
}
}
res
}
}
```
骚操作(暴力思路):
```scala
object Solution {
def sortedSquares(nums: Array[Int]): Array[Int] = {
nums.map(x=>{x*x}).sortWith(_ < _)
}
}
```


-----------------------
Expand Down

AltStyle によって変換されたページ (->オリジナル) /