LeetCode算法入门- Palindrome Number-day2

LeetCode算法入门- Palindrome Number-day2

Palindrome Number

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.

方法一:
将int类型x进行反转,如果反转之后和之前的数字一样,说明是回文,否则不是(记得排除负数的)

class Solution {public boolean isPalindrome(int x) {if(x < 0) return false;//这里是将int类型X进行反转int reverse = 0;int old = x;while(x != 0){reverse = reverse * 10 + x % 10;x = x / 10;}return reverse == old;}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/558893.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

JavaCard概述

什么是JavaCard JavaCard&#xff0c;即Java智能卡。以智能卡硬件系统为基础&#xff0c;通过软件的方式构造一个支持Java程序下载、安装、运行的软/硬件系统。由于引入了虚拟机技术&#xff0c;JavaCard具备硬件无关性&#xff0c;即智能卡应用程序开发与智能卡硬件系统相分离…

LeetCode算法入门- Add Two Numbers-day3

LeetCode算法入门- Add Two Numbers-day3 Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return …

Java并发编程实战————并发技巧小结

可变状态是至关重要的。所有的并发问题都可以归结为如何协调对并发状态的访问。可变状态越少&#xff0c;就越容易确保线程安全性。尽量将域声明为final类型&#xff0c;除非需要它们是可变的。不可变对象一定是线程安全的。不可变对象能极大地降低并发编程的复杂性。它们更为简…

Java核心篇之多线程---day1

Java面试之多线程—day1 一. 线程中sleep方法与wait方法有什么区别&#xff1f; 对于 sleep()方法&#xff0c;我们首先要知道该方法是属于 Thread 类中的。而 wait()方法&#xff0c;则是属于Object 类中的。 在调用 sleep()方法的过程中&#xff0c; 线程不会释放对象锁。而…

LeetCode算法入门- Longest Substring Without Repeating Characters-day4

LeetCode算法入门- Longest Substring Without Repeating Characters-day4 Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. Example 1: Input: “abcabcbb” Output: 3 Explana…

Java 多线程 —— 常用并发容器

引言 本博客基于常用的并发容器&#xff0c;简单概括其基本特性和简单使用&#xff0c;并不涉及较深层次的原理分析和全面的场景用法。 适合对不了解并发容器的同学&#xff0c;工作中遇到类似的场景&#xff0c;能够对文中提到的并发容器留有简单印象就好。 一、Concurrent…

LeetCode算法入门- Longest Palindromic Substring-day5

LeetCode算法入门- Longest Palindromic Substring-day5 Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: “babad” Output: “bab” Note: “a…

Tomcat运行三种模式:http-bio|http-nio|http-apr介绍

转自《tomcat运行三种模式:http-bio|http-nio|http-apr介绍》 Tomcat是一个小型的轻量级应用服务器&#xff0c;也是JavaEE开发人员最常用的服务器之一。不过&#xff0c;许多开发人员不知道的是&#xff0c;Tomcat Connector(Tomcat连接器)有bio、nio、apr三种运行模式&#…

LeetCode算法入门- Reverse Integer-day6

LeetCode算法入门- Reverse Integer-day6 Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 class Solution {public int reverse(int x) {long…

Java工具方法——属性拷贝方法:BeanUtils.copyProperties(Object, Object)

介绍 org.springframework.beans.BeanUtils.copyProperties(Object, Object)是spring 框架的对象工具类&#xff1a;BeanUtils下的一个拷贝对象属性的方法。 官方注释 把给定的源对象属性值拷贝到目标对象中。 注意&#xff1a;源对象类与目标对象类不一定非要完全匹配&…

LeetCode算法入门- String to Integer (atoi)-day7

LeetCode算法入门- String to Integer (atoi)-day7 String to Integer (atoi): Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. The…

LeetCode算法入门- Roman to Integer Integer to Roman -day8

LeetCode算法入门- Roman to Integer -day8 Roman to Integer&#xff1a; 题目描述&#xff1a; Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol    Value I        1 V        5 X        10 L…

Git初学札记(九)————EGit检出远程分支

引言 现在有这样一个使用场景&#xff1a;团队中的其他开发者提交了一个新的特性分支&#xff08;如feature_1&#xff09;&#xff0c;要求我们一同开发&#xff0c;并将自己修改的代码也全部提交到这个分支上去。那么如何将这个分支检出&#xff0c;并将本地检出的分支与这个…

LeetCode算法入门- 3Sum -day9

LeetCode算法入门- 3Sum -day9 题目描述&#xff1a; Given an array nums of n integers, are there elements a, b, c in nums such that a b c 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain dup…

XML学习(一)————XML简介

引言 作为数据传输界鼎鼎大名的扛把子&#xff0c;XML被应用于各个方面&#xff0c;但随着弱结构化标记语言如JSON、YAML等的出现&#xff0c;人们慢慢的脱离了XML的统治&#xff0c;但在互联网早期的发展当中XML是不可或缺的一部分&#xff0c;比如各种微信开发中的数据传输&…

Java核心篇之Java锁--day2

Java核心篇之Java锁–day2 乐观锁&#xff1a;乐观锁是一种乐观思想&#xff0c;即认为读多写少&#xff0c;每次去取数据的时候都认为其他人不会修改&#xff0c;所以不会上锁&#xff1b;但是在更新的时候会判断一下在此期间别人有没有去修改它&#xff0c;如果有人修改的话…

XML学习(二)————属性还是标签?

引言 xml中并没有规则要求我们什么时候使用属性&#xff0c;什么时候使用标签。 属性和标签都可以存储数据&#xff0c;但是在XML的使用中&#xff0c;我们需要探讨一下对属性和标签的选择问题。 约定规则 XML 应该避免使用属性来存储数据&#xff0c;这与HTML的推荐规则不…

LeetCode算法入门- 3Sum Closest -day10

LeetCode算法入门- 3Sum Closest -day10 Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one …

Spring Boot————Web应用启动时自动执行ApplicationListener用法

原文&#xff1a;《web服务启动spring自动执行ApplicationListener的用法》 引言 我们知道&#xff0c;一般来说一个项目启动时需要加载或者执行一些特殊的任务来初始化系统&#xff0c;通常的做法就是用servlet去初始化&#xff0c;但是servlet在使用Spring bean时不能直接注…

LeetCode算法入门- 4Sum -day11

LeetCode算法入门- 4Sum -day11 Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a b c d target? Find all unique quadruplets in the array which gives the sum of target. Note: The solution se…