请问有没有网站兑换quarter的?# Money - 海外理财
a*y
1 楼
sorted array with repeated elements
for given element, find out its range.
e.g. A A B B B B B C C D D E F G, given B, the output should be [2, 6]
binary search的变种
我感觉这个不是O(logn)啊
code是发现repeat次数的
int binarySearch(char* charset, int start, int end, char target)
{
if (charset == NULL) return 0;
if (start == end)
{
if (charset[start] == target) return 1;
else return 0;
}
int mid = start + (end-start)/2;
int left = 0, right = 0;
left = binarySearch(charset,start,mid-1,target);
right = binarySearch(charset, mid+1, end, target);
return (charset[mid] == target ? left+right+1 : left + right);
}
for given element, find out its range.
e.g. A A B B B B B C C D D E F G, given B, the output should be [2, 6]
binary search的变种
我感觉这个不是O(logn)啊
code是发现repeat次数的
int binarySearch(char* charset, int start, int end, char target)
{
if (charset == NULL) return 0;
if (start == end)
{
if (charset[start] == target) return 1;
else return 0;
}
int mid = start + (end-start)/2;
int left = 0, right = 0;
left = binarySearch(charset,start,mid-1,target);
right = binarySearch(charset, mid+1, end, target);
return (charset[mid] == target ? left+right+1 : left + right);
}