首页 > 其他 > 详细

[codility]Distinct

时间:2014-05-04 09:21:51      阅读:421      评论:0      收藏:0      [点我收藏+]

最近在学scala语言,scala代码如下:

import scala.collection.JavaConversions._

object Solution {
    def solution(A: Array[Int]): Int = {
        // write your code in Scala 2.10
        // using quick sort to sort the array first
        scala.util.Sorting.quickSort(A)
        // assign the initial former unique element to be the out of range value
        var formerValue: Int = -10000000
        var uniqueCnt: Int = 0
        
        for(curValue <- A) {
            if(curValue != formerValue) {
                formerValue = curValue
                uniqueCnt += 1
            }
        }
        uniqueCnt
    }
}


[codility]Distinct,布布扣,bubuko.com

[codility]Distinct

原文:http://blog.csdn.net/sunbaigui/article/details/24936075

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!