Two_sum
Scala code
import scala.collection.mutable
object Solution {
def twoSum(nums: Array[Int], target: Int): Array[Int] = {
var map = Map[Int, Int]()
for (i <- 0 until nums.length) {
val complement = target - nums(i)
if (map.contains(complement)) {
return Array(map(complement), i)
}
else {
map += (nums(i) -> i)
}
}
Array(0, 0)
}
}