Skip to main content

Timeline for Check for Palindrome string in Java

Current License: CC BY-SA 3.0

15 events
when toggle format what by license comment
Nov 30, 2016 at 13:37 comment added tkellehe Not quite sure what you mean by not equal in length? How I see it with copying code is that sometimes there really is only one way to do something the fastest (in this case faster than most) therein I say copy it. If the solution is unique (unlike this code here) then I would give credit to whomever. Your implementation is streamlined, but to me my solution is just as streamlined as yours:) To me plagiarism with code is fine as long as you understand it, but that is a hard line to draw. I made that code such that others could use it and hopefully will understand it rather than just copy it.
Nov 30, 2016 at 13:22 comment added user116659 So will this solution work then, if the strings are not equal in length? I feel like at the moment, my original solution is more streamlined - what do you think? Say I was to implement your code, would this be classed as plagiarism / cheating?
Nov 26, 2016 at 4:13 history edited tkellehe CC BY-SA 3.0
added 11 characters in body
Nov 26, 2016 at 4:12 comment added tkellehe Now that will do it:) Thank you for staying persistent! I should have just copied the code from my other answer:(
Nov 26, 2016 at 4:08 history edited tkellehe CC BY-SA 3.0
deleted 1 character in body; edited body
Nov 26, 2016 at 2:32 comment added cbojar Then it will be odd length strings that will give you trouble.
Nov 26, 2016 at 2:30 comment added tkellehe Yes, that is why I did --right to avoid that case:)
Nov 26, 2016 at 2:28 comment added cbojar Yes, it returns that the length is 4, and the characters are indexed <0, 1, 2, 3>. Calling "abba".charAt(4); wil throw an exception.
Nov 26, 2016 at 1:16 comment added tkellehe input.length() returns the length of the string which would be 4.
Nov 26, 2016 at 1:00 comment added cbojar Right would not be 4 at the first iteration, it would be 3 because of zero based indexing. Then it would be (0, 3) => (1, 2) => (2, 1) => (0, 3) => (-1, 4) Index out of bounds.
Nov 25, 2016 at 23:25 comment added tkellehe Well, if you let input.length() equal 4 and input be palindromic then left => 0 and right => 4. So, first iteration they are not equivalent therein we evaluate input.charAt(0) != input.charAt(3). Second iteration left => 1 and right => 3 once again we pass so we evaluate input.charAt(1) != input.charAt(2). Third iteration left => 2 and right => 2 they are equal so we exit. So, we just evaluated every character therein none were skipped:) Yes, I could replace with a < but I get the same result with !=. Unless you can come up with a case where this is not true?
Nov 25, 2016 at 23:07 comment added cbojar You might want to check if left is less than right. For strings of odd length, they will be the same at the middle character but for strings of even length, they will pass each other.
Nov 24, 2016 at 19:58 history edited tkellehe CC BY-SA 3.0
added 5 characters in body
Nov 24, 2016 at 14:20 history edited tkellehe CC BY-SA 3.0
deleted 1 character in body
Nov 24, 2016 at 13:44 history answered tkellehe CC BY-SA 3.0