T家在线题2道# DataSciences - 数据科学
c*z
1 楼
已经悲剧
题1:anagram of a palindrome 要求O(N)
int isAnagrmaOfPalindrome(char *string){
unsigned int bitc = 0, i = 0;
int out = 0;
while(*string){
i = *(string++) - 'a';
bitc ^= (1 << i);
}
out = (int)(bitc & (bitc - 1));
return !out;
}
题2:重新排序整数的digits使其最大化 (e.g. 3515 -> 5531) 要求O(1)
int largestSibling(int N) {
int digit;
int temp = 0;
int output = 0;
for (digit=9;digit>0;digit--)
for (temp=N;temp>0;temp/=10)
if (temp%10==digit) output = output + digit*10;
return output;
}
感想:这和data scientist有什么关系嘛?
题1:anagram of a palindrome 要求O(N)
int isAnagrmaOfPalindrome(char *string){
unsigned int bitc = 0, i = 0;
int out = 0;
while(*string){
i = *(string++) - 'a';
bitc ^= (1 << i);
}
out = (int)(bitc & (bitc - 1));
return !out;
}
题2:重新排序整数的digits使其最大化 (e.g. 3515 -> 5531) 要求O(1)
int largestSibling(int N) {
int digit;
int temp = 0;
int output = 0;
for (digit=9;digit>0;digit--)
for (temp=N;temp>0;temp/=10)
if (temp%10==digit) output = output + digit*10;
return output;
}
感想:这和data scientist有什么关系嘛?