LeetCode #9 - Palindrome Number - Easy

STM32 CubeMX实战:手把手教你用I2C驱动IST8310磁力计(附完整代码) 本文详细介绍了如何使用STM32 CubeMX和I2C驱动IST8310磁力计,从硬件连接到代码实现的完整流程。重点讲解了I2C通信异常处理、传感器初始化序列优化以及中断驱动数据采集方案,帮助开发者快速搭建可靠的地磁场数据采集系统。 阅读详情

Problem

Determine whether an integer is a palindrome. Do this without extra space.

Some hints:

Could negative integers be palindromes? (ie, -1)

If you are thinking of converting the integer to string, note the restriction of using extra space.

You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", 
you know that the reversed integer might overflow. How would you handle such case?

There is a more generic way of solving this problem.

Example

Input:-2147483648
Output:flase

Algorithm

整理一下题意:给定一个整数,判断其是否是回文数。要求不使用额外空间。

由于对空间使用有限制,所以要控制空间复杂度为O(1)。于是很自然地想到利用回文数的性质。回文数的特点在于数字可以形成对称,于是将这个数反过来还是和原来的数相等。于是只要开两个变量来得到翻转后的数字,再将翻转后的数字与原数比较即可。

注意负数均不是回文数。

代码如下。

class Solution {
public:
    bool isPalindrome(int x) {
        if(x<0) return false;

        int temp=x,reverse=0;
        while(temp){
            reverse=reverse*10+temp%10;
            temp/=10;
        }
        if(reverse==x)return true;
        else return false;
    }
};
【ENVI初学】查看影像空间分辨率及重采样 例如,如果线段长度为900米,对应的像素数量为30个,那么影像的空间分辨率为30米。通过计算长度与像素数量的比值,即可得到影像的空间分辨率。,在弹出的对话框中,输入重采样后输出文件的xy分辨率大小。在测量结果窗口中,可以看到该线段的长度以及角度。在影像上点击并拖动鼠标,绘制一条直线段。工具,选择要重采样的影像后点击ok。,避免了插值过程中光谱信息的改变。:最近邻插值法通过选择原始影像中。在ENVI中打开影像后右键选择。指示了每个像素的地理跨度(聚合为一个新像素,通常通过。方法一:查看影像的元数据。 阅读详情

相关推荐

Win10或Win11电脑找不到以太网网络适配器的解决方法

Win10或Win11电脑找不到以太网网络适配器的解决方法

Robot_PLC_HMI_Automation 566

C#LeetCode easy #9 Palindrome Number

9Palindrome Number Determine whether an integer is a palindrome. An integerisapalindrome when itreads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -1...

weixin_30802273的博客 113

告别 Python!C# 直接跑 YOLO 目标检测:工控机边缘推理终极方案

set;set;set;set;set;stringget;set;get;set;get;set;get;set;get;set;告别 Python 依赖,不是排斥 Python 的训练能力,而是为了工程化的极致。在工控机这个资源受限、稳定性要求极高的战场上,是目前最优雅、最高效的解决方案。更少的依赖= 更少的故障点。更快的速度= 更高的产线节拍。更简单的部署= 更低的人力成本。现在,拿起你的 C# 项目,导入那个.onnx。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 370

LeetCode 9 Palindrome Number (easy)——python

题目来源:                       https://leetcode.com/problems/palindrome-number/description/  题目分析:       本题要我们判断一个整数是否是回文数,Do this without extra space.这句,当时我的理解是说在输入时不要留有空格,因此我写的程序较为简单,没有判断溢出等情况,有大神

revivre的博客 282

Leetcode 9. Palindrome Number [easy] [java]

Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example Solution 1 class Solution { public boolean isPalin...

inkhk的博客 233

LeetCode #9. Palindrome Number

Determine whether an integer is a palindrome. An integerisapalindrome when itreads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -121 Output: false Expl...

努力的小飞飞的博客 302

[LeetCode] 009. Palindrome Number (Easy) (C++/Java/Python)

[LeetCode] 009. Palindrome Number (Easy) (C++/Java/Python)

水果君の日常 3269

# leetcode解题报告9. Palindrome Number

leetcode解题报告9. Palindrome Number题目地址 难度是easy题目描述判断一个整数是不是回文串。回文串指从左到右和从右到左是一样。我的思路最直接的思路是把整数转成字符串类型,再判断是不是回文串就行了。但是进一步想,其实可以更直接的,把一个整数翻转(高位变低位),如果是回文串,那翻转结果是和原来整数是一样的。我的代码class Solution { public: b

sysu_xiaoming的博客 343

LeetCode算法-9. Palindrome Number [easy]

Question: 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: ...

小卜妞的博客 216

LeetCode题解-python 9.回文数 Palindrome Number (Easy)

9.回文数 Palindrome Number (Easy) 判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。 示例 3: 输入: 10 输出: false 解释: 从右...

LKY111的专栏 356

LeetCode #9 Palindrome Number

Description Determine whether an integer is a palindrome. Do this without extra space.

菜鸟程序员的成长历程 432

LeetCodePalindrome Number解析

链接:https://leetcode.com/problems/palindrome-number/#/description 难度:Easy 题目:9.Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Some hin...

尾尾部落 126

LeetCode 9. Palindrome Number

题目:Determine whether an integer is a palindrome. Do this without extra space. 思路: 1.利用leetcode #7 的reverse(int x) 2.详见code 代码:思路2 C++ class Solution { public: bool isPalindrome(int ...

weixin_30596735的博客 68

LeetCode小白菜笔记[3]:Palindrome Number

LeetCode小白菜笔记[9]:Palindrome Number

VisualCortex 632

LeetCode #104 - Maximum Depth of Binary Tree - Easy

ProblemGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Subscribe to see which companies ask

Arcome的博客 866

LeetCode #329 - Longest Increasing Path in a Matrix - Hard

ProblemGiven an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outs

Arcome的博客 832

LeetCode #207 - Course Schedule - Medium

Course Schedule Series Course Schedule I: Course Schedule II: ProblemThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example t

Arcome的博客 821

LeetCode #216 - Combination Sum III - Medium

Combination Sum Series Combination Sum I: Combination Sum II: Combination Sum III: ProblemFind all possible combinations of k numbers that add up to a number n, given that only numbers f

Arcome的博客 788

LeetCode #413 - Arithmetic Slices - Medium

Problem A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic

Arcome的博客 698

LeetCode #78 - Subsets - Medium

ProblemGiven a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. ExampleFor example, If nums = [1,2,3], a solution is:[ [3], [1

Arcome的博客 604

LeetCode #319 - Bulb Switcher - Medium

ProblemThere are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off or turn

Arcome的博客 589

C和MATLAB实现的Polar编码和解码.zip

matlab资源

基于SGP4和SDP4模型卫星轨道的计算

预测卫星轨道模型

上一篇: LeetCode #231 - Power of Two - Easy
下一篇: LeetCode #279 - Perfect Squares - Medium
Arcome
博客等级 码龄10年 3粉丝 63原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值