首页 > 代码库 > 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.
注意插入位置对于两个数有三种情况。
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.
找第一个target跟找最后一个target等号放的位置不一样的。
3 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.
没考虑结果等于0的情况。
Bug Free
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。