SHARE
TWEET

Untitled

a guest Jul 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var map = [Range:Int]()
  2.  
  3. func sumRange(_ nums: [Int]) {
  4.    
  5.     for i in 0..<nums.count {
  6.         var sum = 0
  7.        
  8.         var j = i
  9.        
  10.         while j < nums.count {
  11.             sum += nums[j]
  12.             map[Range(i, j)] = sum
  13.             j += 1
  14.         }
  15.     }
  16. }
  17.  
  18. var nums = [-2, 0, 3, -5, 2, -1]
  19. sumRange(nums)
  20.  
  21. let range = Range(0, 5)
  22. if let r = map[range] {
  23.     print(r)
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top