# re: GOOGLE挑战赛练习题3及答案(1000分) 回复
2005-11-29 16:08 by
public class CursorPosition {
public int getPosition(String keystrokes, int N){
int current=0;
int end=N;
int start=0;
for(int i=0;i<keystrokes.length();i++){
char c=keystrokes.charAt(i);
switch(c){
case 'L':
if(current!=start)current--;break;
case 'R':
if(current!=end)current++;break;
case 'H':
current=0;break;
case 'E':
current=N;break;
}
}
return current;
}
public static void main(String[] args) {
CursorPosition c=new CursorPosition2();
System.out.println(c.getPosition("ERLLL",10));
}
}
这道题和你做的几乎一样,效率上应该没有太大差别
但我的了920多分,我觉的是时间的原因,这道题我做的很快就提交了