Guest User

Untitled

a guest
Nov 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import Foundation
  2. import XCTest
  3.  
  4. func getMaxPairwiseProduct(_ numbers: [Int]) -> Int {
  5. var biggest = 0
  6. var secondBiggest = 0
  7.  
  8. for num in numbers {
  9. if num > biggest {
  10. biggest = num
  11. }
  12. }
  13.  
  14. for num in numbers {
  15. if num > secondBiggest && num != biggest {
  16. secondBiggest = num
  17. }
  18. }
  19.  
  20. return biggest * secondBiggest
  21. }
  22.  
  23.  
  24. func printTimeElapsedWhenRunningCode(title:String, operation:()->()) {
  25. let startTime = CFAbsoluteTimeGetCurrent()
  26. operation()
  27. let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
  28. print("Time elapsed for \(title): \(timeElapsed) seconds")
  29. }
  30.  
  31. printTimeElapsedWhenRunningCode(title: "getMaxPairWiseProduct()") {
  32. let result = getMaxPairwiseProduct([1,2,3,4,5,6])
  33. }
Add Comment
Please, Sign In to add comment