码迷,mamicode.com
首页 > 其他好文 > 详细

Bug Free

时间:2016-12-02 22:41:43      阅读:593      评论:0      收藏:0      [点我收藏+]

标签:c99   algo   value   open   sse   can   first   span   round   

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

标签:c99   algo   value   open   sse   can   first   span   round   

原文地址:http://www.cnblogs.com/coldyan/p/6127054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!