-
Notifications
You must be signed in to change notification settings - Fork 2
讀書會第 24次聚會 20210406 #16
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
Conversation
補充算數平均數如何使用 Iteration 來避免 overflow考慮給定 array of k where k == Int.max / 2: http://www.heikohoffmann.de/htmlthesis/node134.html // swift
func average(_ arr: [Int], after: (Double) -> Void) -> Double {
var r:Double = 0
for (i, v) in arr.enumerated() {
r += (Double(v) - r) / Double(i + 1)
after(r)
}
return r
} Example: // Swift
let sut = [1, 2, 4, 5]
var captured = [Double]()
let result = average(sut, after: { i in
captured.append(i)
})
XCTAssertEqual(result, 3.0)
XCTAssertEqual(captured, [1.0, 1.5, 2.3333333333333335, 3.0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danishuotw
我發現我自己在使用 while 的時候,不太喜歡 繼續邏輯
,而是使用 阻擋邏輯
,例如
while (left < right)
我喜歡寫成 while true { if left >= right {break} ....
我的那個有專有名詞 a loop and a half
。
提出來看看有沒有討論空間。
Find Peak Element Recursive
Co-authored-by: Dani Shuo <yusatrtru@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Search for a Range
in TypeScript
@ytyubox 不過我有時會再加上 Example: // 當 leftIndex > rightIndex、或是 left 的值跟 target 相等時,就離開迴圈
while (!(leftIndex > rightIndex || nums[leftIndex] === targetValue)) {
...
...
}
|
This comment has been minimized.
This comment has been minimized.
@ytyubox |
@louis222220 關於你的反邏輯:
我看到你用 |
Co-authored-by: Dani Shuo <yusatrtru@gmail.com>
Co-authored-by: Dani Shuo <yusatrtru@gmail.com>
@danishuotw 這個我就加進來喔,你還是可以繼續討論,不過因為範圍已經過去了,要用留言的方式聊了。 |
LeetCode 讀書會第 24次聚會
leetcode 讀書會通知
項目: 第 24 次聚會
目的: 線上一起寫題目, 由有想法的人帶領, 先解題, 再看該題有趣的解法
時間: 4/06 (二) 20:00 ~ 21:00
地點: google meet 線上 (前 10 分鐘預備鏈接)
解題項目: https://leetcode.com/explore/learn/card/binary-search/126/template-ii/
共筆: GitHub https://github.com/programmingbookclub/Leetcode-club