scala练习题 leetcode1.两数之和

scala。。我太难了

object Solution {
    def twoSum(nums: Array[Int], target: Int): Array[Int] = {
        var res: Array[Int] = new Array[Int](2);
        val len = nums.length;

       for( i <- 0 to len-2 ; j <- i+1 to len-1 ){
            if(nums(i) + nums(j) == target){
                res(0) = i;
                res(1) = j;
                
            }
       }
        return res;
    }
}

发布了164 篇原创文章 · 获赞 64 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/qq_20417499/article/details/104139537
今日推荐