标签:
/* * 330. Patching Array * 2016-7-9 by Mingyang * hehe */ public int minPatches(int[] nums, int n) { if (n <= 0) return 0; nums = nums == null ? new int[0] : nums; int current_ind = 0, ret = 0; long boundary_val = 1, sum = 0; while (boundary_val <= n) { if (current_ind < nums.length && nums[current_ind] <= boundary_val) { sum += nums[current_ind++]; boundary_val = sum + 1; } else { ret++; sum += boundary_val; boundary_val = sum + 1; } } return ret; }
标签:
原文地址:http://www.cnblogs.com/zmyvszk/p/5657040.html