programming challenge Nickel 2018

作成日:2018/4/4

Nickel 2018 challenge - Codility

初アワード頂きました~嬉しい~(˘ω˘)
しかし相変わらずperformanceが0%なのは進歩0!
素直に何処が無駄なんだろう。

【Codility Silver Award for the Nickel 2018 Challenge】
https://app.codility.com/cert/view/cert32Z7M4-QVRPZWTWE4MM63HF/

// you can also use imports, for example:
// import java.util.*;

// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");

class Solution {

    int ans = 0;

    public void make(boolean[] p) {
        if (p.length > 0) {
            boolean[] node = new boolean[p.length -1];
            for(int i = 0; i < p.length; i++) {
                if(p[i] == true) {
                    ans++;

                    if(i < node.length) {
                        node[i] = true;    
                    }
                    if(i > 0) {
                        node[i - 1] = true;
                    }
                }
            }

            if (p.length - 1 > 0) {
                make(node);   
            }
        }

    }

    public int solution(boolean[] P) {
        // write your code in Java SE 8

        make(P);
        return ans;
    }
}