Algorithm: Max Counters

后端 未结 22 1844
孤城傲影
孤城傲影 2021-02-04 07:40

I have the following problem:

You are given N counters, initially set to 0, and you have two possible operations on them:

  • increase(X) − counter X is increa
22条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 08:20

    Ruby Codility Code that got 100/100

    def solution(a)
    
      if a.length < 3
          0
      end
      a.sort!
      for i in 2..a.length - 1
        if (a[i-2] + a[i-1]) > a[i]
          return 1
        end
      end
     0
    end
    

提交回复
热议问题