Skip to content

Commit

Permalink
Create: 0167-two-sum-ii-input-array-is-sorted.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
krishna1m committed Apr 16, 2023
1 parent b3d1baa commit 165e20f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scala/0167-two-sum-ii-input-array-is-sorted.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object Solution {
def twoSum(numbers: Array[Int], target: Int): Array[Int] = {
def loop(p1: Int, p2: Int): Array[Int] = {
if(numbers(p1) + numbers(p2) == target) Array(p1 + 1, p2 + 1)
else if(numbers(p1) + numbers(p2) > target) loop(p1, p2 - 1)
else loop(p1 + 1, p2)
}
loop(0, numbers.length - 1)
}
}

0 comments on commit 165e20f

Please sign in to comment.