python: recursive check to determine whether string is a palindrome

前端 未结 6 1322
死守一世寂寞
死守一世寂寞 2021-01-19 17:11

My task is to define a procedure is_palindrome, that takes as input a string, and returns a boolean indicating if the input string is a palindrome. In this case a single let

6条回答
  •  盖世英雄少女心
    2021-01-19 17:28

    Respuesta en Java

    public class Varios {
    
    /**
     * @param args the command line arguments
     */
      public static void main(String[] args) {
        System.out.println( pali("anitalavalatina"));
      }
      static boolean pali(String palabra){
        System.out.println(palabra);
        if (palabra.length()-1<2) 
                return true;
        if(palabra.charAt(0)!=palabra.charAt(palabra.length()-1)) return false;
        return pali(palabra.substring(1,palabra.length()-1));
      }
    
    }
    

提交回复
热议问题