String paremeter do not accept Multi-Line String!


  • 0
    J

    Multi-Line Input gives Run-Time Error!

    Input:

    "
    "
    

    Code:

    public class Solution {
        public boolean isPalindrome(String s) {
            
            s = onlyAlphaNumeric(s);
            s = s.toLowerCase();
            
            StringBuilder s1 = new StringBuilder();
            s1.append(s);
            s1 = s1.reverse(); 
            
            return s.equals(new String(s1));
        }
        
        String onlyAlphaNumeric(String s){
            for(int i=0; i<s.length(); i++){
                char a = s.charAt(i);
                if(Character.isLetter(a) || Character.isDigit(a)){
                    continue;
                }
                else{
                    s = s.substring(0, i) + "" + s.substring(i+1, s.length());
                    i--;
                }
            }
            return s;
        }
    }
    

    Even simple return statement in function gives Run-Time Error

    public class Solution {
        public boolean isPalindrome(String s) {
            return true;
        }
    }
    

    Is there any way to accept Multi-Line String value?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.