Bug Free
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章