zoukankan      html  css  js  c++  java
  • 9. Palindrome Number(回文数)(leetcode)

    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.
    

    Follow up:

    Coud you solve it without converting the integer to a string?

    方法一:数学方法

    1、我做的时候没想到x>res这一点。这个的好处显而易见,可以减少一半的比较次数。

    时间复杂度:o(n/2)                   运行时间:80ms                  占用空间:41.1 MB

    方法二:栈

    这个方法的运行时间比上一个大,但是占的内存小了一点。

    时间复杂度:o(n/2)                 运行时间:90ms              占用空间:40.5 MB

     680. Valid Palindrome II(可删除一个数再判断是不是回文数)

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.

    Example 1:

    Input: "aba"
    Output: True
    

    Example 2:

    Input: "abca"
    Output: True
    Explanation: You could delete the character 'c'.
    

    Note:

      1. The string will only contain lowercase characters a-z. The maximum length of the string is 50000.

    方法一:双指针

    1、主程序里如果遇到再判断的问题记得子函数让代码更清晰。

    时间复杂度:o(n)                 运行时间:17ms              占用空间:37.7 MB

    苟有恒,何必三更眠五更起;最无益,莫过一日暴十日寒。
  • 相关阅读:
    supermall遇到的问题
    github建立仓库
    【Teradata】9794 ERRAMPOUTOFPHYSPACE error解决方法
    MPP大规模并行计算数据库与分布式数据库的区别
    【English】20190515
    商业数据分析的四个层次
    学会学习(Learning how to learn)
    【English】20190513
    【Teradata】DEL语句产生的锁
    【Teradata】开启LockLogger与dumplocklog工具使用(含lokdisp工具说明)
  • 原文地址:https://www.cnblogs.com/shaer/p/10412223.html
Copyright © 2011-2022 走看看