Given an integer array representing different length of wood. Cut them into small pieces to guarantee you could have equal or more than k pieces with the same length
create function to count the piece sum of L
if count >= k, means k is small, set start = mid
publicintwoodCut(int[] L,int k) {// find the longest woodint max =0;for (int i =0; i <L.length; i++){ max =Math.max(L[i], max); }int start =1, end = max;while(start +1< end){int mid = start + (end-start)/2;if (count(L, mid)>= k){ start = mid; }else{ end = mid; } }if(count(L, start)>= k){return start; }if(count(L, end)>= k){return end; }return0;}// count the total pieces of wood length Lprivateintcount(int[] L,int len){int piece =0;for (int i =0; i <L.length; i++){ piece += (int)L[i]/len; }return piece;}