Skip to content

Commit 4e8e4de

Browse files
authored
Merge pull request neetcode-gh#2419 from krishna1m/0167-two-sum-ii-input-array-is-sorted
Create: 0167-two-sum-ii-input-array-is-sorted.scala
2 parents ee29457 + 165e20f commit 4e8e4de

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object Solution {
2+
def twoSum(numbers: Array[Int], target: Int): Array[Int] = {
3+
def loop(p1: Int, p2: Int): Array[Int] = {
4+
if(numbers(p1) + numbers(p2) == target) Array(p1 + 1, p2 + 1)
5+
else if(numbers(p1) + numbers(p2) > target) loop(p1, p2 - 1)
6+
else loop(p1 + 1, p2)
7+
}
8+
loop(0, numbers.length - 1)
9+
}
10+
}

0 commit comments

Comments
 (0)