Leetcode 504 Base 7
Given an integer, return its base 7 string representation.
Example 1:
Input: 100
Output: “202”
Example 2:
Input: -7
Output: “-10”
Note: The input will be in range of [-1e7, 1e7].
這個題是將十進位制轉化為七進位制,方法即為不斷模7餘下的數的串,程式中需要考慮為空值和負數的時候。
1)
class Solution {
public:
string convertToBase7(int num) {
string res;
bool is_neg = false;
if(num < 0){
num *= -1;
is_neg = true;
}else if(!num){
res += '0';
}
while(num != 0){
res += to_string(num % 7);
num /= 7;
}
if(is_neg){
res += "-";
}
return string(res.rbegin(),res.rend());
}
};
相關文章
- 503/504 問題
- leetcode-7LeetCode
- Leetcode 7 Reverse IntegerLeetCode
- CF504E Misha and LCP on Tree
- nginx 502 和 504 超時演示Nginx
- nginx “504 Gateway Time-out”錯誤NginxGateway
- LeetCode(7)--.反轉整數LeetCode
- LeetCode 第 7 題(Reverse Integer)LeetCode
- oracle baseOracle
- base/publicPath
- Ubuntu baseUbuntu
- ORA-600(504)(row cache objects)錯誤Object
- 運維相關 如何解決504報錯運維
- Nginx中502和504錯誤詳解Nginx
- 分散式base分散式
- [Spark base]-01Spark
- SQL management baseSQL
- oracle base topicOracle
- base.jsJS
- oracle-baseOracle
- base標籤
- base64
- LeetCode7.整數反轉 JavaScriptLeetCodeJavaScript
- LeetCode7:ReverseInteger(整數反轉)LeetCode
- LeetCode - 解題筆記 - 7 - Reverse IntegerLeetCode筆記
- 使用adodb504a連線oracle9iOracle
- 轉載:ORA-00600: internal error code, arguments: [504]Error
- cout.setf(ios_base::fixed,ios_base::floatfield);iOS
- 【LeetCode從零單排】No.7 Reverse IntegerLeetCode
- Base64 原理
- Base64原理
- Views and Base Tables (243)View
- 正規實體平臺官網[TL504.COM].
- 實體平臺註冊官網[TL504.COM].
- 新錦江手機app官網[TL504.COMAPP
- 果博東方手機app官網[TL504.COM]APP
- 華納國際手機app官網[TL504.COM]APP
- Nginx報504 gateway timeout錯誤的解決方法NginxGateway