题解 | #在二叉树中找到两个节点的最近公共祖先#
和为S的连续正数序列
http://www.nowcoder.com/practice/c451a3fd84b64cb19485dad758a55ebe
import java.util.; public class Solution{ public ArrayList<ArrayList> FindContinuousSequence(int sum){ ArrayList<ArrayList> result = new ArrayList<>(); if(sum < 3) return result; int low = 1,high = 2; while(high > low){ int cur = (high + low)(high - low +1) / 2; if(cur == sum){ ArrayList list = new ArrayList<>(); for(int i = low;i <= high;i++){ list.add(i); } result.add(list); low ++; }else if(cur < sum){ high ++; }else{ low ++; } } return result;
}
}
我居南半坡 文章被收录于专栏
多刷题,积蓄力量,欢迎讨论

查看12道真题和解析