File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,31 @@ impl Solution {
183183}
184184```
185185
186+ #### Swift
187+
188+ ``` swift
189+ class Solution {
190+ func temperatureTrend (_ temperatureA : [Int ], _ temperatureB : [Int ]) -> Int {
191+ var maxTrend = 0
192+ var currentTrend = 0
193+
194+ for i in 0 ..< temperatureA.count - 1 {
195+ let changeA = temperatureA[i + 1 ] - temperatureA[i]
196+ let changeB = temperatureB[i + 1 ] - temperatureB[i]
197+
198+ if (changeA == 0 && changeB == 0 ) || (changeA * changeB > 0 ) {
199+ currentTrend += 1
200+ maxTrend = max (maxTrend, currentTrend)
201+ } else {
202+ currentTrend = 0
203+ }
204+ }
205+
206+ return maxTrend
207+ }
208+ }
209+ ```
210+
186211<!-- tabs: end -->
187212
188213<!-- solution: end -->
Original file line number Diff line number Diff line change 1+ class Solution {
2+ func temperatureTrend( _ temperatureA: [ Int ] , _ temperatureB: [ Int ] ) -> Int {
3+ var maxTrend = 0
4+ var currentTrend = 0
5+
6+ for i in 0 ..< temperatureA. count - 1 {
7+ let changeA = temperatureA [ i + 1 ] - temperatureA[ i]
8+ let changeB = temperatureB [ i + 1 ] - temperatureB[ i]
9+
10+ if ( changeA == 0 && changeB == 0 ) || ( changeA * changeB > 0 ) {
11+ currentTrend += 1
12+ maxTrend = max ( maxTrend, currentTrend)
13+ } else {
14+ currentTrend = 0
15+ }
16+ }
17+
18+ return maxTrend
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments