From bfb00b905780046aed636bc889c81adf676d3100 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Tue, 7 Jan 2025 00:43:42 +0100 Subject: [PATCH] feat: add swift implementation to lcp problem: No.61 (#3932) --- .../README.md" | 25 +++++++++++++++++++ .../Solution.swift" | 20 +++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 "lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/Solution.swift" diff --git "a/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/README.md" "b/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/README.md" index 14bac274a24df..faf7cedef5e2f 100644 --- "a/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/README.md" +++ "b/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/README.md" @@ -183,6 +183,31 @@ impl Solution { } ``` +#### Swift + +```swift +class Solution { + func temperatureTrend(_ temperatureA: [Int], _ temperatureB: [Int]) -> Int { + var maxTrend = 0 + var currentTrend = 0 + + for i in 0.. 0) { + currentTrend += 1 + maxTrend = max(maxTrend, currentTrend) + } else { + currentTrend = 0 + } + } + + return maxTrend + } +} +``` + diff --git "a/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/Solution.swift" "b/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/Solution.swift" new file mode 100644 index 0000000000000..b0807755dc2a1 --- /dev/null +++ "b/lcp/LCP 61. \346\260\224\346\270\251\345\217\230\345\214\226\350\266\213\345\212\277/Solution.swift" @@ -0,0 +1,20 @@ +class Solution { + func temperatureTrend(_ temperatureA: [Int], _ temperatureB: [Int]) -> Int { + var maxTrend = 0 + var currentTrend = 0 + + for i in 0.. 0) { + currentTrend += 1 + maxTrend = max(maxTrend, currentTrend) + } else { + currentTrend = 0 + } + } + + return maxTrend + } +} \ No newline at end of file