+ 2
How will i correct my this code as my last word is not coming and also i want to remove my space???
i.e. i want the output as like this Output: vernda https://code.sololearn.com/cvjdD5Jjnz91/?ref=app Gaurav Agrawal Pro Coder Donna
13 Respostas
+ 15
â doubt comments on code:
1)j<=l will cause IndexOutOfBound exception : as j will be ranging from (i+1) to l, that means for j=l, exception will occur.
2)replacing by '' will cause an error , so replaced by ' ' :
U can make use of syntax : stringValue.replace(String,String);
So U can use of : stringValue.replace(charValue+"", "");
//here we converted charValue to String by adding "".
[also replacing by "" will change the length of s will cause IndexOutOfBound exceptions]
3)why "a" not printed:
i moved from 0 to l-1, j moved from i+1 to l-1
but for i=l-1, inner loop having j will not work,
that means j will be having value of previous iteration, that will be l-2+1=l-1
//so if() in outer loop [c!=c1] will be false & nothing will be printed.
âBy now many solutions are available, but by considering your original code some fixes:
1)s+=" "; //adding 1 space to s to tackle 3rd pt.
2)(char==' '?""?char) in print stat.
//still,there is need of improvement in original logic
+ 11
Michal I like your Streams approach much better than mine. I was wondering if there was a reduce method available. Now I know. đđ
Also, your method 3 with booleans was simple, yet clean and effective.
Nicely done. đđ
+ 10
Rewa Mathur I further simplified the code you fixed.
Harsh Agrawal See if you can identify the subtle changes made by Rewa, then by me
https://code.sololearn.com/chbstUcNz7xl/?ref=app
+ 10
Michal I believe so. However, it wasn't clear to me either. đ
Rewa Mathur Here's a version of the code using Java Streams.
https://code.sololearn.com/csFU16d9EA0R/?ref=app
I gotta admit, it's a bit ugly. But I'm quite biased towards LINQ in C#. đ€
+ 7
Few different examples
https://code.sololearn.com/ctbeeDQzZx9U/?ref=app
+ 5
Harsh Agrawal If you look a few comments up, Gaurav Agrawal posted a nice breakdown of the issues in your code.
+ 3
Idea of the code is to remove duplicates?
+ 1
Thnxzz David Carroll,Rewa Mathur ,Michal ,Gaurav Agrawal
But how wll i correct my original code i.e. my code???
+ 1
Rewa Mathur No bro i want to say how wll i correct my original code??? This code is too different from my code!!!