C++ | Leetcode C++题解之第504题七进制数

题目:

题解:

cpp 复制代码
class Solution {
public:
    string convertToBase7(int num) {
        if (num == 0) {
            return "0";
        }
        bool negative = num < 0;
        num = abs(num);
        string digits;
        while (num > 0) {
            digits.push_back(num % 7 + '0');
            num /= 7;
        }
        if (negative) {
            digits.push_back('-');
        }
        reverse(digits.begin(), digits.end());
        return digits;
    }
};
相关推荐
Lhan.zzZ2 小时前
笔记_2026.4.28_004
c++·ide·笔记·qt
wuminyu3 小时前
专家视角看Java字节码加载与存储指令机制
java·linux·c语言·jvm·c++
木喃的井盖4 小时前
无锁队列细节
c++·工程
王老师青少年编程4 小时前
csp信奥赛C++高频考点专项训练之字符串 --【字符串基础】:输出亲朋字符串
c++·字符串·csp·高频考点·信奥赛·专项训练·输出亲朋字符串
Navigator_Z5 小时前
LeetCode //C - 1033. Moving Stones Until Consecutive
c语言·算法·leetcode
WBluuue5 小时前
数据结构与算法:莫队(一):普通莫队与带修莫队
c++·算法
KuaCpp5 小时前
C++面向对象(速过复习版)
开发语言·c++
智者知已应修善业8 小时前
【51单片机不用数组动态数码管显示字符和LED流水灯】2023-10-3
c++·经验分享·笔记·算法·51单片机
AI进化营-智能译站9 小时前
ROS2 C++开发系列16-智能指针管理传感器句柄|告别ROS2节点内存泄漏与野指针
java·c++·算法·ai
报错小能手9 小时前
好好讲讲移动构造 移动赋值
c++