SHARE
TWEET

Untitled

a guest Sep 16th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def twoSumConstSpace(list: Array[Int], k: Int): Boolean = {
  2.   util.Arrays.sort(list)
  3.   var i = 0
  4.   var j = list.length - 1
  5.   while (i < j) {
  6.     val sum = list(i) + list(j)
  7.     if (sum == k) {
  8.       return true
  9.     } else if (sum < k) {
  10.       i += 1
  11.     } else {
  12.       j -= 1
  13.     }
  14.   }
  15.   false
  16. }
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
 
Top