codewars021: Sequences and Series

https://www.codewars.com/kata/5254bd1357d59fbbe90001ec/train/javajava

// https://www.codewars.com/kata/5254bd1357d59fbbe90001ec/train/java
package codewars;
public class Sequence{
  private static long[] arr = new long[10001];
  static{
    arr[1] = 1;
    for(int i=2; i<= 10000; i++){
      arr[i] = arr[i - 1] + i;
    }
  }
  public static long getScore(long n){
    if(n <= 10000){
      return arr[(int)n] * 50L;
    }
    return getScore(n - 1) + 50 * n;
  }
}
相關文章
相關標籤/搜索