Results 1 to 4 of 4
Thread: Timed Out!?
- 08-24-2011, 08:12 PM #1
Timed Out!?
this Is question: Given a string and a non-empty word string, return a version of the original String where all chars have been replaced by pluses ("+"), except for appearances of the word string which are preserved unchanged.
plusOut("12xy34", "xy") → "++xy++"
plusOut("12xy34", "1") → "1+++++"
plusOut("12xy34xyabcxy", "xy") → "++xy++xy+++xy"
why my code give Timed Out?
Java Code:public String plusOut(String str, String word) { int v=0; String res = ""; for(int i=0;i<str.length();i++){ v = str.indexOf(word, i); for(int z=i;z<v;z++){ res+="+"; } res += word; i += v-1; } return res; }
- 08-24-2011, 08:17 PM #2
What values does the i variable have as the loop is executed? And the v and z variables.
Print them out to see.
- 08-24-2011, 11:54 PM #3
finally i could solved it!
Java Code:public String plusOut(String str, String word) { int v=0; String res = ""; for(int i=0;i<str.length();i++){ v = str.indexOf(word, i); if(str.indexOf(word, i)<0){ for(int z=i;z<=str.length();z++){ res+="+"; } break; } for(int z=i;z<v;z++){ res+="+"; } res += word; i = v-1+word.length(); } return res; }
- 08-24-2011, 11:55 PM #4
Similar Threads
-
Timed response button
By fresh83 in forum New To JavaReplies: 3Last Post: 05-17-2011, 08:01 PM -
javamail, Connection timed out
By OmerHalit in forum NetworkingReplies: 11Last Post: 04-12-2010, 07:02 AM -
Connection Timed Out
By sukatoa in forum NetworkingReplies: 2Last Post: 10-27-2009, 03:20 PM -
solution for connection timed out
By santhosh_el in forum NetworkingReplies: 0Last Post: 10-03-2009, 07:55 AM -
i am getting connection timed out
By santhosh_el in forum NetworkingReplies: 1Last Post: 08-25-2009, 06:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks