例如,”abcdef”循环右移2个就变为”efabcd”
popo实现了一个,不过需要O(n)的额外空间程序:void LoopMove(char * pStr,int steps){ int len = strlen(pStr); char *s = new char[len+1]; int count = 0; char *temp = pStr; while (*pStr) { s[(count+steps)%len] = *pStr; pStr++; count++; } s[len] = ‘\0′; strcpy(temp,s); delete []s;}
最近想出了个空间为O(1),时间为O(n)的算法就是只通过数组指针移动和交换来实现
int LoopMove2(char *p, int i, int t, int s, int m){ int n = strlen(p); int [...]
interview's archives
编写一个函数,作用是把一个char组成的字符串循环右移n个
Posted by zeaster in September 25th 2006
Google 面试第一题解法
Posted by zeaster in September 25th 2006
Solve this cryptic equation, realizing of course that values for M and E could be interchanged. No leading zeros are allowed.
WWWDOT - GOOGLE = DOTCOM
思路:穷举法,式子中共有9个不同的字母,数字0-9有10个,因此就从10个数字中任取9个,排成一列,这样分别对应了式子中的字母。然后判断当前取出的这9个数,是否满足条件。本程序中用check2 函数判断,另外需要考虑WE是可以互换,但不可以相同
答案:只有两组解777589 - 188103 = 589486777589 - 188106 = 589483
程序:Perm1.javapackage org.chao.perm;
public class Perm1 { public static void main(String[] args) { [...]
Search
Most Comments
- blogsync with gui coming, import your wordpress to blogger (68)
- blogsync 0.3 released, comments can be imported. (20)
- A tool that import all posts from wordpress to blogger in python (8)
- Mac OS X上成功使用dopod 696 wm5.0 连 cmwap上网 (7)
- blogsync 2.0 released, import your wordpress to blogger from rss xml file or online (5)
- How to decompile .dex file on Android (4)
- Inconvenienced when using Contact Content Provider on Android (3)
- 统一Mac OS X,Windows XP/Vista以及linux的系统时间 (2)
- Windows XP/Vista vs Mac OS X 软件对比清单 (2)
- 性能准则之一:在遍历集合前一定要判断集合是否为空 (2)
- A python script that get posts from wordpress by httplib (1)
- blogsync FAQ (1)
Recent Comments
- zeaster in blogsync 0.3 released, comments can…
- the writer in blogsync 0.3 released, comments can…
- zeaster in Inconvenienced when using Contact C…
- sshwsfc in Inconvenienced when using Contact C…
- zeaster - How t… in Inconvenienced when using Contact C…
- zeaster - Incon… in How to decompile .dex file on Andro…
- meng_xx in How to decompile .dex file on Andro…
- Elia in blogsync with gui coming, import yo…
- Yichao in blogsync with gui coming, import yo…
- Elia in blogsync with gui coming, import yo…