【叠甲】是某家公司的面试题,还挺出名的,题目简单,但搭配上面试官也透露出浓浓的pua味道。 ---------------也算秋招时候的趣闻了。---------------
/**
* @author Bruce
*/
public class Summation {
private Summation(){}
private static volatile Summation instance = null;
public static Summation getInstance(){
if (instance == null){
synchronized (Summation.class){
if (instance == null){
instance = new Summation();
}
}
}
return instance;
}
public static Integer count(int start, int end){
return (start + end) % 2 == 1 ?
(((end + start - 1) >> 1) * ((end - start - 1) + 1) + end) :
(((end + start) >> 1) * (end - start) + 1);
}
}