首页 > 代码库 > Bug Free

Bug Free

1 Search Insert Position---NOT BUG FREE

技术分享
1 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
2 
3 You may assume no duplicates in the array.
View Code

注意插入位置对于两个数有三种情况。

 

2 Search in a Big Sorted Array---NOT BUG FREE

技术分享
1 Given a big sorted array with positive integers sorted by ascending order. The array is so big so that you can not get the length of the whole array directly, and you can only access the kth number by ArrayReader.get(k) (or ArrayReader->get(k) for C++). Find the first index of a target number. Your algorithm should be in O(log k), where k is the first index of the target number.
2 
3 Return -1, if the number doesn‘t exist in the array.
4 
5  Notice
6 
7 If you accessed an inaccessible index (outside of the array), ArrayReader.get will return 2,147,483,647.
View Code

找第一个target跟找最后一个target等号放的位置不一样的。

 

Wood Cut ---NOT BUG FREE

技术分享
1 Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you could have equal or more than k pieces with the same length. What is the longest length you can get from the n pieces of wood? Given L & k, return the maximum length of the small pieces.
2 
3  Notice
4 
5 You couldn‘t cut wood into float length.
View Code

没考虑结果等于0的情况。

 

Bug Free