Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- import XCTest
- func getMaxPairwiseProduct(_ numbers: [Int]) -> Int {
- var biggest = 0
- var secondBiggest = 0
- for num in numbers {
- if num > biggest {
- biggest = num
- }
- }
- for num in numbers {
- if num > secondBiggest && num != biggest {
- secondBiggest = num
- }
- }
- return biggest * secondBiggest
- }
- func printTimeElapsedWhenRunningCode(title:String, operation:()->()) {
- let startTime = CFAbsoluteTimeGetCurrent()
- operation()
- let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
- print("Time elapsed for \(title): \(timeElapsed) seconds")
- }
- printTimeElapsedWhenRunningCode(title: "getMaxPairWiseProduct()") {
- let result = getMaxPairwiseProduct([1,2,3,4,5,6])
- }
Add Comment
Please, Sign In to add comment