leetCode练题——9. Palindrome Number】的更多相关文章

1.题目 9. 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,…
这是悦乐书的第310次更新,第331篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第179题(顺位题号是754).你站在无限数字线的0号位置.在目的地有个target.在每次移动中,您可以向左或向右移动.在第n次移动(从1开始)期间,你可以走n步.返回到达目的地所需的最少步骤数.例如: 输入:target = 3 输出:2 说明:在第一步中,我们从0步进到1.在第二步,我们从1步骤到3. 输入:target = 2 输出:3 说明:在第一步中,我们从0步进到1.在第…
这是悦乐书的第287次更新,第304篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第155题(顺位题号是680).给定非空字符串s,最多可以删除一个字符. 判断它是否是回文.例如: 输入:"aba" 输出:true 输入:"abca" 输出:true 说明:可以删除字符"c"让其变为回文. 注意:该字符串仅包含小写字符a-z. 字符串的最大长度为50000. 本次解题使用的开发工具是eclipse,jdk使用的版本是…
这是悦乐书的第222次更新,第235篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第89题(顺位题号是414).给定非空的整数数组,返回此数组中的第三个最大数字.如果不存在,则返回最大数量.时间复杂度必须在O(n)中.例如: 输入:[3,2,1] 输出:1 说明:第三个最大值为1. 输入:[1,2] 输出:2 说明:第三个最大值不存在,因此返回最大值2. 输入:[2,2,3,1] 输出:1 说明:请注意,此处的第三个最大值表示第三个最大不同的数字.值为2的两个数字都…
这是悦乐书的第220次更新,第232篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第87题(顺位题号是409).给定一个由小写或大写字母组成的字符串,找到可以用这些字母构建的最长的回文长度.这是区分大小写的,例如"Aa"在这里不被视为回文.例如: 输入:"abccccdd" 输出:7 说明:可以建造的最长的回文是"dccaccd",其长度为7. 注意:假设给定字符串的长度不超过1,010. 本次解题使用的开发工具是e…
这是悦乐书的第219次更新,第231篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第86题(顺位题号是405).给定一个整数,写一个算法将其转换为十六进制.对于负整数,使用二进制补码方法.例如: 输入:26 输出:"1a" 输入:-1 输出:"ffffffff" 注意: 十六进制(a-f)中的所有字母必须为小写. 十六进制字符串不得包含额外的前导0.如果数字为零,则由单个零字符"0"表示;否则,十六进制字符串中的第一…
这是悦乐书的第174次更新,第176篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第33题(顺位题号是125).给定一个字符串,确定它是否是回文,只考虑字母数字字符并忽略大小写.空字符串是有效回文.例如: 输入:"A man, a plan, a canal: Panama" 输出:true 输入:"race a car" 输出:false 本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,环境是win7 64位系统,使…
9. Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the res…
导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始几行代码内容,有一些不规范的地方,比如函数名大小写问题等等:更合理的代码实现参考我的github repo 1.读题 Determine whether an integer is a palindrome. Do this without extra space. 这一题描述很简单,判断一个数字是…
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                Explanat…
LeetCode第9题 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. F…
题目等级:Easy 题目描述: 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 -12…
LeetCode真是个好东西,本来闲了一下午不想看书,感觉太荒废时间了就来刷一道题.能力有限,先把easy的题目给刷完. Determine whether an integer is a palindrome. Do this without extra space. 确定一个整数是否是回文. 做这个没有额外的空间. 这道题毕竟是easy级别的,花了大概5分钟就写出来了.我的思路就是判断回文要首尾一一对照么,如果把int转换成string类型的话比较字符就方便多了. class Solutio…
1.题目 38. Count and Say The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as …
1.题目 12. Integer to Roman 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 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one's added together. Twelve i…
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should retu…
题目: 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…
1.题目 88. Merge Sorted Array——Easy Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough…
1.题目 66. Plus One——easy Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a sin…
1.题目 53. Maximum Subarray——Easy Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanation: [4,-1,2,1] has th…
1.题目 35. Search Insert Position Easy 1781214Add to ListShare Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in th…
1.题目13. Roman to Integer 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 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one's added together. Twelve is…
#回文数#Method1:将整数转置和原数比较,一样就是回文数:负数不是回文数#这里反转整数时不需要考虑溢出,但不代表如果是C/C++等语言也不需要考虑class Solution(object):    def isPalindrome(self, x):        """        :type x: int        :rtype: bool        """        if x<0:return False    …
1.题目:   7. Reverse Integer 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 Note:Assume we are dealing with an environment which could…
1.题目 70. Climbing Stairs——Easy You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a positive integer. Example 1:…
1.题目 67. Add Binary——easy Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example 1: Input: a = "11", b = "1"Output: "100"Example 2:…
1.题目 58. Length of Last Word——Easy Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string. If the la…
1.题目 28. Implement strStr()——Easy Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Input: haystack = "hello", needle = "ll" Output: 2 Example 2: Inp…
1.题目 27. Remove Element——Easy Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1)…
1.题目 26. Remove Duplicates from Sorted Array--Easy Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifyi…