首页 > 其他 > 详细

leetcode刷题笔记九 回文数 Scala版本

时间:2020-04-12 00:22:35      阅读:90      评论:0      收藏:0      [点我收藏+]

leetcode刷题笔记九 回文数 Scala版本

源地址:leetcode刷题笔记九 回文数 Scala版本

问题描述:

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

Example 1:

Input: 121
Output: true

Example 2:

Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.

Example 3:

Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

简要思路分析:

判断回文的主要方式是比较原串与反转串是否一致或者串本身是否具有对称性。由于Scala具有相关函数,这里我们简单比较一下原串与反转串是否一致即可。

代码补充:

object Solution {
    def isPalindrome(x: Int): Boolean = {
      if (x.toString == x.toString.reverse) return true  else return false
    }
}

leetcode刷题笔记九 回文数 Scala版本

原文:https://www.cnblogs.com/ganshuoos/p/12682987.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!