網(wǎng)址:https://leetcode.com/problems/reverse-integer/
題意:
反轉(zhuǎn)數(shù)字,正負不變.
分析:
思路不言而喻,
重點在有些刁鉆的輸入輸出上.
解法:
由于疏忽正負,又要用到mod.
自然想到abs...
不過abs對int其實不完全適用.
使用前,判斷1下是否是INT_MIN或Integer.MIN_VALUE
我又不想記住這個正負,就用x / abs(x)來解決...
那末還需要斟酌0/0是違背數(shù)學(xué)規(guī)律的.
這個也需要單獨拿出來.
那末越界的情況自然也是要斟酌,屬于常規(guī)了.
代碼:
https://github.com/LiLane/leetcode/blob/master/java/007-ReverseInteger⑵01504291907.java
https://github.com/LiLane/leetcode/blob/master/c%2B%2B/007-ReverseInteger⑵01504291908.cpp