Valid Palindrome by ifenil · Pull Request #2 · NirmalSilwal/Data-Structure-and-Algorithm-Java-interview-kit · GitHub
Skip to content

Valid Palindrome#2

Open
ifenil wants to merge 2 commits into
NirmalSilwal:masterfrom
ifenil:master
Open

Valid Palindrome#2
ifenil wants to merge 2 commits into
NirmalSilwal:masterfrom
ifenil:master

Conversation

@ifenil

@ifenil ifenil commented Oct 3, 2020

Copy link
Copy Markdown

Valid Palindeome From Leetcode August Challange ;
explanation of code line by line through comment;
easily understandable and simple code
it passed all the test cases;

@ifenil

ifenil commented Oct 3, 2020

Copy link
Copy Markdown
Author

@NirmalSilwal

Copy link
Copy Markdown
Owner

Hi @ifenil, could you add another approach or more optimized solution. That would be better PR if you are considering hactoberfest.
What do you think?

@ifenil

ifenil commented Oct 3, 2020

Copy link
Copy Markdown
Author

@NirmalSilwal ,
I tried but I couldn't find optimized solution.
I think it's easy to understandable for beginners like me.

@javadev

javadev commented Mar 17, 2022

Copy link
Copy Markdown

@vikasganiga05 vikasganiga05 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My solution to the problem. Missing some edge cases(which can be added later).

public class Palindrome {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Please enter the string: ");
    String str = input.nextLine();
    input.close();

    int i = 0;
    int j = str.length() - 1;
    while (i < j) {
      if (str.charAt(i) == str.charAt(j)) {
        i++;
        j--;
      } else {
        System.out.printf("The string %s is not a Palindrome. \n", str);
        return;
      }
    }
    System.out.printf("The string %s is a Palindrome. \n", str);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants