diff --git "a/lcp/LCP 33. \350\223\204\346\260\264/README.md" "b/lcp/LCP 33. \350\223\204\346\260\264/README.md" index 6511af87a08b2..301d9505b50df 100644 --- "a/lcp/LCP 33. \350\223\204\346\260\264/README.md" +++ "b/lcp/LCP 33. \350\223\204\346\260\264/README.md" @@ -168,6 +168,34 @@ function storeWater(bucket: number[], vat: number[]): number { } ``` +#### Swift + +```swift +class Solution { + func storeWater(_ bucket: [Int], _ vat: [Int]) -> Int { + let maxVat = vat.max() ?? 0 + if maxVat == 0 { + return 0 + } + + let n = vat.count + var ans = Int.max + + for x in 1...maxVat { + var y = 0 + for i in 0.. 0 { + y += max(0, (vat[i] + x - 1) / x - bucket[i]) + } + } + ans = min(ans, x + y) + } + + return ans + } +} +``` + diff --git "a/lcp/LCP 33. \350\223\204\346\260\264/Solution.swift" "b/lcp/LCP 33. \350\223\204\346\260\264/Solution.swift" new file mode 100644 index 0000000000000..c1ade70414605 --- /dev/null +++ "b/lcp/LCP 33. \350\223\204\346\260\264/Solution.swift" @@ -0,0 +1,23 @@ +class Solution { + func storeWater(_ bucket: [Int], _ vat: [Int]) -> Int { + let maxVat = vat.max() ?? 0 + if maxVat == 0 { + return 0 + } + + let n = vat.count + var ans = Int.max + + for x in 1...maxVat { + var y = 0 + for i in 0.. 0 { + y += max(0, (vat[i] + x - 1) / x - bucket[i]) + } + } + ans = min(ans, x + y) + } + + return ans + } +}