返回介绍

solution / 2100-2199 / 2119.A Number After a Double Reversal / README_EN

发布于 2024-06-17 01:03:09 字数 2479 浏览 0 评论 0 收藏 0

2119. A Number After a Double Reversal

中文文档

Description

Reversing an integer means to reverse all its digits.

  • For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.

Given an integer num, reverse num to get reversed1, then reverse reversed1 to get reversed2. Return true _if_ reversed2 _equals_ num. Otherwise return false.

 

Example 1:

Input: num = 526
Output: true
Explanation: Reverse num to get 625, then reverse 625 to get 526, which equals num.

Example 2:

Input: num = 1800
Output: false
Explanation: Reverse num to get 81, then reverse 81 to get 18, which does not equal num.

Example 3:

Input: num = 0
Output: true
Explanation: Reverse num to get 0, then reverse 0 to get 0, which equals num.

 

Constraints:

  • 0 <= num <= 106

Solutions

Solution 1

class Solution:
  def isSameAfterReversals(self, num: int) -> bool:
    return num == 0 or num % 10 != 0
class Solution {
  public boolean isSameAfterReversals(int num) {
    return num == 0 || num % 10 != 0;
  }
}
class Solution {
public:
  bool isSameAfterReversals(int num) {
    return num == 0 || num % 10 != 0;
  }
};
func isSameAfterReversals(num int) bool {
  return num == 0 || num%10 != 0
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文