limca500ml
BAN USERrace1: a1 a2 a3 a4 a5, winner: a1
race2: b1 b2 b3 b4 b5, winner: b1
race3: c1 c2 c3 c4 c5, winner: c1
race4: d1 d2 d3 d4 d5, winner: d1
race5: e1 e2 e3 e4 e5, winner: e1
race6: a1 b1 c1 d1 e1, winner: a1
rece7:b1 a2 a3 c1 b2
Could you plz explain more ?
- limca500ml January 24, 2013int checker = 0;
// readt each char one by one
for (int i = 0; i < str.length(); ++i) {
// get unique ASCII value for current char
int val = str.charAt(i) - 'a';
// if bit is not on for that "val"th place
if ((checker & (1 << val)) > 0)
return false;
// Turn on the bit at val place and or to checker
checker |= (1 << val);
}
return true;
// Checker is a bit map. We have one to one mapping between "n"th bit and "n"th char
// Just turning on that bit if char present .
Please let me know if it still unclear
public static boolean isUniqueChars(String str) {
int checker = 0;
for (int i = 0; i < str.length(); ++i) {
int val = str.charAt(i) - 'a';
if ((checker & (1 << val)) > 0)
return false;
checker |= (1 << val);
}
return true;
}
NitinGupta180: Please check all other threads before asking any question. This question/solution is already present @
_Careercup.com/question?id=6899782
int atoi(const char *str)
{
int i=0;
while ( *str )
{
// i<<3 + i<<1 = i*10, to change decimal place of int
i = (i<<3) + (i<<1) + ((*str) - '0');
++str;
}
return i;
}
BinaryTree* sortedArrayToBST(int arr[], int start, int end) {
- limca500ml February 20, 2013if (start > end) return NULL;
int mid = (start + start) / 2;
BinaryTree *node = new BinaryTree(arr[mid]);
node->left = sortedArrayToBST(arr, start, mid-1);
node->right = sortedArrayToBST(arr, mid+1, end);
return node;
}
BinaryTree* sortedArrayToBST(int arr[], int n) {
return sortedArrayToBST(arr, 0, n-1);
}