From b4cb58a159d38f8a644afe0586e3a5797b4582b2 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Mon, 6 Jan 2025 07:51:21 +0100 Subject: [PATCH 1/2] feat: add swift implementation to lcp problem: No.61 --- .../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..f06315df55d0c 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 From ed7d0e6b17e2d1f1c66bb9c3ec47357a3a588c1d Mon Sep 17 00:00:00 2001 From: klever34 Date: Mon, 6 Jan 2025 06:54:27 +0000 Subject: [PATCH 2/2] style: format code and docs with prettier --- .../README.md" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 f06315df55d0c..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" @@ -190,11 +190,11 @@ 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) @@ -202,7 +202,7 @@ class Solution { currentTrend = 0 } } - + return maxTrend } }