Easy Math
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example1:
Input: 121
Output: true
Example2:
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.
Example3:
Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Follow up:
Could you solve it without converting the integer to a string?
解答
主要采用简单的数学算术理论,除法与求余,从尾部迭代构造新的整数与输入参数比较,判断两个值是否相等
func isPalindrome(x int) bool {
if x < 0 {
return false
}
originX, reverseX := x, 0
for x > 0 {
reverseX = reverseX*10 + x%10
x /= 10
}
return reverseX == originX
}
func isPalindrome(x int) bool {
if x < 0 || (x%10 == 0 && x != 0) {
return false
}
reverseX := 0
for x > reverseX {
reverseX = reverseX*10 + x%10
x /= 10
}
return reverseX == x || x == reverseX/10
}
- init
- clone
- add
- status
- diff
- commit
- reset
- rm,mv
- stash
- branch
- checkout
- merge
- log
- tag
- remote
- fetch, pull
- push
- log
- diff
Our Software Dependency Problem
The rest of this section outlines some considerations when inspecting a package and deciding whether to depend on it.
- Design
- Code Quality
- Testing
- Debugging
- Maintenance
- Usage
- Security
- Licensing
- Dependencies
- Test the dependency
- Abstract the dependency
- Isolate the dependency
- Avoid the dependency
- Upgrade the dependency
- Watch your dependency