a********d 发帖数: 195 | 1 是不是加个条件就行了?
public static int bsII(int[] arr, int target)
{
int leftIdx = 0;
int rightIdx = arr.Length - 1;
int mid = 0;
if (target < arr[0]) return -1;
if (target > arr[rightIdx]) return rightIdx;
while (leftIdx < rightIdx)
{
mid = (leftIdx + rightIdx) / 2;
if (arr[mid] == target) return mid;
if (arr[mid] < target)
{
if (... 阅读全帖 |
|
l*********8 发帖数: 4642 | 2 下面是我的程序
vector a 存储intervals [a[0] a[1]), [a[2] a[3]), [a[4] a[5]) ....
开始写在纸上,后来在电脑上调试才发现有几个bugs. 一遍写对不容易啊:-(
#include
#include
using namespace std;
void MergeToIntervals(vector & a, int left, int right)
{
int leftIdx = lower_bound(a.begin(), a.end(), left) - a.begin();
int rightIdx = upper_bound(a.begin(), a.end(), right) - a.begin();
int vectorSizeChange = 0;
int leftPos = -1; // left boundary's final position in the vector. -1 means it w... 阅读全帖 |
|
l*********8 发帖数: 4642 | 3 下面是我的程序
vector a 存储intervals [a[0] a[1]), [a[2] a[3]), [a[4] a[5]) ....
开始写在纸上,后来在电脑上调试才发现有几个bugs. 一遍写对不容易啊:-(
#include
#include
using namespace std;
void MergeToIntervals(vector & a, int left, int right)
{
int leftIdx = lower_bound(a.begin(), a.end(), left) - a.begin();
int rightIdx = upper_bound(a.begin(), a.end(), right) - a.begin();
int vectorSizeChange = 0;
int leftPos = -1; // left boundary's final position in the vector. -1 means it w... 阅读全帖 |
|
i******t 发帖数: 22541 | 4 自己编辑可以通过啊 放在leetcode 说time error。。。
咋回事啊
class Solution {
public:
int minimumTotal(vector > &triangle) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int minV = INT_MAX;
int m = triangle.size();
vector > vecV;
vecV.resize(m);
if(m==0) return 0;
if(m==1) return triangle[0][0];
vecV[0][0]=triangle[0][0];
for(int i=1;i
{
int... 阅读全帖 |
|
a***r 发帖数: 93 | 5
不错,不过:
if(rightIdx>size())
shouldn't it be:
if(rightIdx<=size()-1)
? |
|