a********r 发帖数: 218 | 1 Given the character array {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’}
create a function/method that can shift the characters to the right by a
number of iterations specified in a parameter.
the prototype would look like:
void shift(char *arry, unsigned int length, unsigned int shift_count);
A call to this method with a shift count of 1 would return the result {’h’
,‘a’,’b’,’c’,’d’,’e’,’f’,’g’} , and 5 would return the result
{‘d’,’e’,’f’,’g’,’h’,’a’,’b’,’c’}.
Thanks so much! | c****p 发帖数: 6474 | 2 abcdefgh -> cba hgfed -> defgh abc
}
result
【在 a********r 的大作中提到】 : Given the character array {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’} : create a function/method that can shift the characters to the right by a : number of iterations specified in a parameter. : the prototype would look like: : void shift(char *arry, unsigned int length, unsigned int shift_count); : A call to this method with a shift count of 1 would return the result {’h’ : ,‘a’,’b’,’c’,’d’,’e’,’f’,’g’} , and 5 would return the result : {‘d’,’e’,’f’,’g’,’h’,’a’,’b’,’c’}. : Thanks so much!
| r*******y 发帖数: 1081 | 3 revese twice ?
}
result
【在 a********r 的大作中提到】 : Given the character array {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’} : create a function/method that can shift the characters to the right by a : number of iterations specified in a parameter. : the prototype would look like: : void shift(char *arry, unsigned int length, unsigned int shift_count); : A call to this method with a shift count of 1 would return the result {’h’ : ,‘a’,’b’,’c’,’d’,’e’,’f’,’g’} , and 5 would return the result : {‘d’,’e’,’f’,’g’,’h’,’a’,’b’,’c’}. : Thanks so much!
| r*******n 发帖数: 344 | 4 abcdefgh -> abcdefghabcdefgh -> abc defghabc defgh
从index = length - shift_count 开始截取长度为length的array
}
result
【在 a********r 的大作中提到】 : Given the character array {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’} : create a function/method that can shift the characters to the right by a : number of iterations specified in a parameter. : the prototype would look like: : void shift(char *arry, unsigned int length, unsigned int shift_count); : A call to this method with a shift count of 1 would return the result {’h’ : ,‘a’,’b’,’c’,’d’,’e’,’f’,’g’} , and 5 would return the result : {‘d’,’e’,’f’,’g’,’h’,’a’,’b’,’c’}. : Thanks so much!
| c****p 发帖数: 6474 | 5 需要O(n)空间
【在 r*******n 的大作中提到】 : abcdefgh -> abcdefghabcdefgh -> abc defghabc defgh : 从index = length - shift_count 开始截取长度为length的array : : } : result
| a********r 发帖数: 218 | 6 @chenpp,
you are genius!!!!!
【在 c****p 的大作中提到】 : 需要O(n)空间
| r*******n 发帖数: 344 | 7 For in-place replacement, yours is better.
【在 c****p 的大作中提到】 : 需要O(n)空间
| f*******t 发帖数: 7549 | 8 好办法,赞
【在 c****p 的大作中提到】 : abcdefgh -> cba hgfed -> defgh abc : : } : result
| c****p 发帖数: 6474 | 9 谬赞。。
编程之美上的样题。
【在 a********r 的大作中提到】 : @chenpp, : you are genius!!!!!
| a********r 发帖数: 218 | 10 Given the character array {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’}
create a function/method that can shift the characters to the right by a
number of iterations specified in a parameter.
the prototype would look like:
void shift(char *arry, unsigned int length, unsigned int shift_count);
A call to this method with a shift count of 1 would return the result {’h’
,‘a’,’b’,’c’,’d’,’e’,’f’,’g’} , and 5 would return the result
{‘d’,’e’,’f’,’g’,’h’,’a’,’b’,’c’}.
Thanks so much! | | | c****p 发帖数: 6474 | 11 abcdefgh -> cba hgfed -> defgh abc
}
result
【在 a********r 的大作中提到】 : Given the character array {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’} : create a function/method that can shift the characters to the right by a : number of iterations specified in a parameter. : the prototype would look like: : void shift(char *arry, unsigned int length, unsigned int shift_count); : A call to this method with a shift count of 1 would return the result {’h’ : ,‘a’,’b’,’c’,’d’,’e’,’f’,’g’} , and 5 would return the result : {‘d’,’e’,’f’,’g’,’h’,’a’,’b’,’c’}. : Thanks so much!
| r*******y 发帖数: 1081 | 12 revese twice ?
}
result
【在 a********r 的大作中提到】 : Given the character array {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’} : create a function/method that can shift the characters to the right by a : number of iterations specified in a parameter. : the prototype would look like: : void shift(char *arry, unsigned int length, unsigned int shift_count); : A call to this method with a shift count of 1 would return the result {’h’ : ,‘a’,’b’,’c’,’d’,’e’,’f’,’g’} , and 5 would return the result : {‘d’,’e’,’f’,’g’,’h’,’a’,’b’,’c’}. : Thanks so much!
| r*******n 发帖数: 344 | 13 abcdefgh -> abcdefghabcdefgh -> abc defghabc defgh
从index = length - shift_count 开始截取长度为length的array
}
result
【在 a********r 的大作中提到】 : Given the character array {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’} : create a function/method that can shift the characters to the right by a : number of iterations specified in a parameter. : the prototype would look like: : void shift(char *arry, unsigned int length, unsigned int shift_count); : A call to this method with a shift count of 1 would return the result {’h’ : ,‘a’,’b’,’c’,’d’,’e’,’f’,’g’} , and 5 would return the result : {‘d’,’e’,’f’,’g’,’h’,’a’,’b’,’c’}. : Thanks so much!
| c****p 发帖数: 6474 | 14 需要O(n)空间
【在 r*******n 的大作中提到】 : abcdefgh -> abcdefghabcdefgh -> abc defghabc defgh : 从index = length - shift_count 开始截取长度为length的array : : } : result
| a********r 发帖数: 218 | 15 @chenpp,
you are genius!!!!!
【在 c****p 的大作中提到】 : 需要O(n)空间
| r*******n 发帖数: 344 | 16 For in-place replacement, yours is better.
【在 c****p 的大作中提到】 : 需要O(n)空间
| f*******t 发帖数: 7549 | 17 好办法,赞
【在 c****p 的大作中提到】 : abcdefgh -> cba hgfed -> defgh abc : : } : result
| c****p 发帖数: 6474 | 18 谬赞。。
编程之美上的样题。
【在 a********r 的大作中提到】 : @chenpp, : you are genius!!!!!
| b*********6 发帖数: 19 | | q********c 发帖数: 1774 | 20 Facebook phone interview question? | p*******o 发帖数: 3564 | 21 deque? O(n) extra space |
|