半数集

来源:互联网 发布:c语言编程判断题 编辑:程序博客网 时间:2024/05/02 06:46
package algorithms;/** * Created by sprint on 16-10-19. */public class HalfOfSets {    private int[] arrays = new int[10000];//默认为0    public int numberOfResult(int key) {        if (arrays[key] > 0)    return arrays[key];        int result = 1;        for (int i = 1; i <= key/2; i++) {            result += numberOfResult(i);        }        arrays[key] = result;        return result;    }    public static void main(String[] args) {        HalfOfSets hos = new HalfOfSets();        System.out.println(hos.numberOfResult(15));    }}

0 0
原创粉丝点击