标签:
/* * 163.Missing Ranges * 2016-6-3 by Mingyang * 自己的代码未贴出来。原理就是只要这个是count发的下一个,就只加count, * 否则就把count加了以后再加自己 */ public List<String> findMissingRanges(int[] A, int lower, int upper) { List<String> result = new ArrayList<String>(); int pre = lower - 1; for(int i = 0 ; i <= A.length ; i++){ int after = i == A.length ? upper + 1 : A[i]; if(pre + 2 == after){ result.add(String.valueOf(pre + 1)); }else if(pre + 2 < after){ result.add(String.valueOf(pre + 1) + "->" + String.valueOf(after - 1)); } pre = after; } return result; }
标签:
原文地址:http://www.cnblogs.com/zmyvszk/p/5558351.html