CodeWars:Sum of odd numbers

来源:互联网 发布:做淘宝赚钱吗怎么做 编辑:程序博客网 时间:2024/06/05 23:05

题目:

我的解:

个人觉得最棒解:
public static long rowSumOddNumbers(long n)  {    return n * n * n;  }
理由:

       ((n - 1) * n + 1) * n + (n - 1) * n

==>n * n * n

原创粉丝点击