SENI #035
SENI #035
SENI 035
Algoritma
11. Wadah Dengan Air Terbanyak
Kesulitan: Sedang
Diberikan n bilangan bulat non-negatif a<sub style=“display: inline;”>1</sub>, a<sub style=“display: inline;”>2</sub>, …, a<sub style=“display: inline;”>n </sub>, yang masing-masing mewakili sebuah titik pada koordinat (i, a<sub style=“display: inline;”>i</sub>). n garis vertikal digambar sedemikian rupa sehingga kedua titik ujung garis i berada di (i, a<sub style=“display: inline;”>i</sub>) dan (i, 0). Carilah dua garis yang bersama sumbu x membentuk suatu wadah, sehingga wadah tersebut berisi air paling banyak.
**Catatan: **Anda tidak boleh memiringkan wadah dan n minimal 2.

<small style=“display: inline;”>Garis vertikal di atas diwakili oleh array [1,8,6,2,5,4,8,3,7]. Dalam hal ini, luas maksimum air (bagian biru) yang dapat ditampung wadah adalah 49.</small>
Contoh:
Input: [1,8,6,2,5,4,8,3,7]
Output: 49
Solusi
Bahasa: cepat
最容易想出来的解决方案应该就是两层循环,不出意外会超时,一般两层循环的在leetcode都会超时。
class Solution {
func maxArea(_ height: [Int]) -> Int {
var maxArea = 0
for i in 0..<height.count {
let left = height[i]
for j in (i + 1)..<height.count {
let right = height[j]
let rightIndex = j
let tem = min(left, right) * (rightIndex - i)
maxArea = max(maxArea, tem)
}
}
return maxArea
}
}
perusahaan asuransi kesehatan, perusahaan asuransi O(N) perusahaan asuransi kesehatan办法:
class Solution {
func maxArea(_ height: [Int]) -> Int {
var maxArea = 0
var left = 0
var right = height.count - 1
var leftValue = 0
var rightValue = 0
while left < right {
leftValue = height[left]
rightValue = height[right]
maxArea = max(maxArea, min(leftValue, rightValue) * (right - left))
if leftValue > rightValue {
right -= 1
}
else{
left += 1
}
}
return maxArea
}
}
Ulasan
HR谈Penawaran: https://dandan2009.github.io/2019/12/10/job-negotiation-for-programmers-the-basic-principles/
Kiat
-
Tips1: zsh alias 怎么加参数?
alias 我们知道
alias ios='cd /Users/dan/Documents/wanan/ios/iv && pod install --no-repo-update && open iv.xcworkspace'在终端输入
ios就可以执行三条命令。
那么怎么alias 命令怎么带参数呢,答案就是用函数。
deletefile() { rm -rf $1 echo rm -rf $1 } alias dele=deletefile在终端输入 dele 2.txt, 就会执行
rm -rf 2.txt echo rm -rf 2.txt -
Tips2: iOS menggunakan fitur NSDecimalNumber
@property(nonatomic, strong) NSDecimalNumber* price;//< 单位:元接口返回是NSNumber类型,有些数字解析会有问题,比如实际数据是9. 8, AFN akan mendapatkan 9,800000000000001, dan akan ada lebih dari 9.80000000001,
解决办法,重写set 方法, NSDecimalNumberHandler处理一下。
- (void)setPrice:(NSDecimalNumber *)price{ NSDecimalNumberHandler *handler = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundDown scale:2 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO]; _price = [price decimalNumberByRoundingAccordingToBehavior:handler]; }; RoundingMode: NSRoundDown只舍不入 scale : 2 保留两位小数 -
Tips3: Mac ssh-key如何配置多个
在 ~/.ssh 目录下新建config文件或者编辑config文件
konfigurasi:
# github 的ssh-key Host github.com User xxxx@gmail.com PreferredAuthentications publickey IdentityFile ~/.ssh/github # coding.net的ssh-key Host gitlab.coding.net User xxxx@qq.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa
Bagikan
你怎么看待华为251事件?
What to read next
Want more posts about ARTS?
Posts in the same category are usually the best next step for reading more on this topic.
View same categoryWant to keep following #iOS?
Tags are useful for related tools, specific problems, and similar troubleshooting notes.
View same tagWant to explore another direction?
If you are not sure what to read next, return to the homepage and start from categories, topics, or latest updates.
Back home