007.reverse-integer

本文介绍了一种实现32位整数翻转的方法,包括处理正负数的情况,并提供了解题代码示例。

给定一个范围为 32 位 int 的整数,将其颠倒。

例 1:

输入: 123
输出:  321

 

例 2:

输入: -123
输出: -321

 

例 3:

输入: 120
输出: 21

解题思路:

    先要判断该数字是否大于0,通过一个变量来保存该数字的符号位,然后提取该数字的最后一位,变成ans的第一位,直到遍历此数字的所有位。


解题代码:

        sign = x<0 and -1 or 1
        ans=0
        x=abs(x)
        while x:
            ans=ans*10+x%10
            x=x/10
        return sign*ans if ans<=0x7fffffff else 0
        


注意:最后判断的是答案是否为32位而不是原数字




我在cmake之后想要make -j$(nproc)编译,但是并没有编译D:\third_party\ceres-solver\cmake_build>make -j$(nproc) make: the '-j' option requires a positive integer argument Usage: make [options] [target] ... Options: -b, -m Ignored for compatibility. -B, --always-make Unconditionally make all targets. -C DIRECTORY, --directory=DIRECTORY Change to DIRECTORY before doing anything. -d Print lots of debugging information. --debug[=FLAGS] Print various types of debugging information. -e, --environment-overrides Environment variables override makefiles. -E STRING, --eval=STRING Evaluate STRING as a makefile statement. -f FILE, --file=FILE, --makefile=FILE Read FILE as a makefile. -h, --help Print this message and exit. -i, --ignore-errors Ignore errors from recipes. -I DIRECTORY, --include-dir=DIRECTORY Search DIRECTORY for included makefiles. -j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg. --jobserver-style=STYLE Select the style of jobserver to use. -k, --keep-going Keep going when some targets can't be made. -l [N], --load-average[=N], --max-load[=N] Don't start multiple jobs unless load is below N. -L, --check-symlink-times Use the latest mtime between symlinks and target. -n, --just-print, --dry-run, --recon Don't actually run any recipe; just print them. -o FILE, --old-file=FILE, --assume-old=FILE Consider FILE to be very old and don't remake it. -O[TYPE], --output-sync[=TYPE] Synchronize output of parallel jobs by TYPE. -p, --print-data-base Print make's internal database. -q, --question Run no recipe; exit status says if up to date. -r, --no-builtin-rules Disable the built-in implicit rules. -R, --no-builtin-variables Disable the built-in variable settings. --shuffle[={SEED|random|reverse|none}] Perform shuffle of prerequisites and goals. -s, --silent, --quiet Don't echo recipes. --no-silent Echo recipes (disable --silent mode). -S, --no-keep-going, --stop Turns off -k. -t, --touch Touch targets instead of remaking them. --trace Print tracing information. -v, --version Print the version number of make and exit. -w, --print-directory Print the current directory. --no-print-directory Turn off -w, even if it was turned on implicitly. -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE Consider FILE to be infinitely new. --warn-undefined-variables Warn when an undefined variable is referenced. This program built for x86_64-pc-msys Report bugs to <bug-make@gnu.org>
最新发布
08-01
在使用 `make` 命令时,`-j` 参数用于指定并行执行的作业数,以加快构建过程。然而,在某些情况下,使用 `-j` 参数可能会导致错误,例如资源竞争、依赖关系未正确声明或目标文件冲突等问题。以下是一些常见的解决方法和注意事项: 1. **检查依赖关系** 并行执行时,如果目标之间的依赖关系没有正确声明,可能会导致构建失败。确保所有目标的依赖项都已正确定义,并且没有遗漏必要的前置条件。例如,多个目标可能依赖于同一个中间文件,若该文件未被正确声明为依赖项,可能导致并行执行时出现竞争条件。 2. **减少并行作业数** 如果系统资源有限(如内存不足或 CPU 核心数较少),可以尝试减少 `-j` 的参数值。例如,使用 `make -j4` 而不是 `make -j8`,以降低系统负载并避免资源耗尽的问题。 3. **使用 `.NOTPARALLEL` 特殊目标** 如果某些目标不支持并行执行,可以在 Makefile 中定义 `.NOTPARALLEL` 特殊目标,以强制这些目标按顺序执行。例如: ```makefile .NOTPARALLEL: ``` 4. **启用 `--output-sync` 选项** 在并行执行时,多个作业的输出可能会交错,影响调试。可以通过 `--output-sync` 选项来同步输出,使每个目标的输出保持连续。例如: ```bash make -j4 --output-sync ``` 5. **使用 `-k` 或 `--keep-going` 参数** 当某些目标无法成功构建时,可以使用 `-k` 参数让 `make` 继续尝试构建其他目标,而不是立即停止。这有助于识别更多潜在问题,而不是在第一个失败处中断。例如: ```bash make -j4 -k ``` 6. **检查文件系统和权限问题** 并行执行时,多个作业可能会同时尝试写入相同的文件或目录,导致权限冲突或文件锁定问题。确保所有目标操作的文件路径是唯一的,或在操作前检查文件是否已被其他进程占用。 7. **更新 Make 工具版本** 某些旧版本的 `make` 工具可能存在对并行执行的支持不完善的问题。可以尝试更新到最新版本,以获得更好的并行执行支持和错误修复。 8. **调试并行执行问题** 可以通过 `--debug` 选项启用调试模式,查看详细的执行过程,从而定位问题根源。例如: ```bash make -j4 --debug ``` ### 示例:使用 `-j` 参数并启用同步输出 ```bash make -j4 --output-sync ``` ### 示例:并行执行失败后继续构建其他目标 ```bash make -j4 -k ``` ### 示例:强制某些目标顺序执行 ```makefile .NOTPARALLEL: all: target1 target2 target1: sleep 2 && echo "Building target1" target2: sleep 1 && echo "Building target2" ``` 通过上述方法,通常可以解决大部分与 `-j` 参数相关的错误。如果问题仍然存在,建议检查具体的错误信息,并结合日志进行详细分析。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值