mirror of
https://github.com/d0zingcat/infloop.life.git
synced 2026-05-13 23:16:47 +00:00
updates
This commit is contained in:
@@ -52,6 +52,8 @@ Recently, I've been...
|
||||
|
||||
| Name | Progress |
|
||||
| --- | --- |
|
||||
| [獵魔士](https://www.netflix.com/hk/title/80189685) |
|
||||
| [](https://baike.baidu.com/item/罗小黑战记/22902442) |
|
||||
| [罗小黑战记](https://baike.baidu.com/item/罗小黑战记/22902442) |
|
||||
| [哪吒之魔童降世](https://movie.douban.com/subject/26794435//) |
|
||||
| [中国机长](https://movie.douban.com/subject/30295905/) |
|
||||
|
||||
@@ -34,3 +34,9 @@ menu = "main"
|
||||
### iOS
|
||||
|
||||
- [Infuse](https://firecore.com/infuse):视频播放
|
||||
|
||||
## 网站
|
||||
|
||||
### 下载
|
||||
|
||||
- [Old version](http://www.oldversion.com):下载软件历史版本
|
||||
@@ -8,6 +8,12 @@ draft: false
|
||||
|
||||
这篇文章讲用于记录我日常遇到的一些问题的解决和一些小的hacks。话不多说,let's begin.
|
||||
|
||||
|
||||
- start zookeeper error: ERROR Unexpected exception, exiting abnormally (org.apache.zookeeper.server.ZooKeeperServerMain)
|
||||
java.io.IOException: No snapshot found, but there are log entries. Something is broken!
|
||||
|
||||
手动删除掉zookeeper下的数据后可以正常启动 `rm -rf /usr/local/var/lib/zookeeper`
|
||||
|
||||
- nginx测试配置是否正确
|
||||
|
||||
The -c flag indicates a certain configuration file will follow; the -t flag tells Nginx to test our configuration.
|
||||
@@ -38,9 +44,9 @@ chmod 777 /tmp/.X11-unix/X1
|
||||
brew install kafka
|
||||
```
|
||||
To have launchd start kafka now and restart at login:
|
||||
`brew services start kafka`
|
||||
brew services start kafka
|
||||
Or, if you don’t want/need a background service you can just run:
|
||||
`zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties && kafka-server-start /usr/local/etc/kafka/server.properties`
|
||||
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties && kafka-server-start /usr/local/etc/kafka/server.properties
|
||||
|
||||
- 误删macOS唯一一个administrator的用户admin组,不小心使用了`sudo dseditgroup -o edit -a $(whoami) -t user admin` (本意只是想从wheel组里面删掉)命令把系统上唯一一个具有超级管理员权限的用户的组权限给删了,导致使用sudo命令会提示 `$(user) not in sudoers file, this incident will be reported....`
|
||||
|
||||
|
||||
67
source/_posts/leetcode-7-reverse-integer-md.md
Normal file
67
source/_posts/leetcode-7-reverse-integer-md.md
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
title: leetcode-7-reverse-integer.md
|
||||
tags: ["leetcode", "solution"]
|
||||
date: 2019-11-26 20:56:46
|
||||
---
|
||||
|
||||
7. Reverse Integer
|
||||
Given a 32-bit signed integer, reverse digits of an integer.
|
||||
Example 1:
|
||||
|
||||
Input: 123
|
||||
Output: 321
|
||||
Example 2:
|
||||
|
||||
Input: -123
|
||||
Output: -321
|
||||
Example 3:
|
||||
|
||||
Input: 120
|
||||
Output: 21
|
||||
|
||||
Note:
|
||||
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
|
||||
|
||||
<!--more-->
|
||||
|
||||
题意很简单,就是数字反转,例如123-\>321。解法也比较简单,就是每次取除10的模数(然后除10取整),原数乘10累加。例如123就是1+10*((0+3)*10+2)=321。需要注意有两个点,一个是可能数字是120000,那么就不能简单地通过字符串反转来做(算数方法做是没问题的);另一个就是有边界,边界是4字节的有符号整型数字的范围,也就是 $$[-2^{-31}, 2^{31}-1]$$。
|
||||
|
||||
我的做法比较粗暴,判断还有一位的时候用边界去减了除10,和当前数比较大小即可(其实这么做有问题,如果test case长度不是2的31次方位,比如100位的数字,那也会最后一步才会判断是否溢出,对于python这种科学计算型语言不会有问题,因为底层已经处理了大数运算。对于C、Java等传统语言,这么写就会有问题。当然,也可以上来就手动判一下数字长度,如果大于10就直接返回0,不过我没写。),也没想到居然这么写过了,代码如:
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def reverse(self, x: int) -> int:
|
||||
n = 0
|
||||
flag = 1
|
||||
if x < 0:
|
||||
flag = -1
|
||||
x = -x
|
||||
while x > 0:
|
||||
if x < 10:
|
||||
if flag == 1 and n > ((1<<31)-1-x)/10 or flag == -1 and n > ((1<<31)-1)/10:
|
||||
return 0
|
||||
n = n * 10 + x % 10
|
||||
x = x // 10
|
||||
return flag * n
|
||||
```
|
||||
|
||||
|
||||
|
||||
然后就是参考题解了。发现有两个地方可以改进代码。一个其实不用一开始就把负数转换为正数,因为带符号数累加之后符号还是在的;还有一个是判断条件可以做修改为判断为当前数是不是大于MAXINT/10,因为如果大于的话那么下一次x10就必然溢出;如果等于那么判断尾数是不是大于等于8(正数时)、小于等于-9(负数时)。
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Refer
|
||||
|
||||
[7. Reverse Integer](https://leetcode.com/problems/reverse-integer/)
|
||||
|
||||
[7. Reverse Integer](https://leetcode.com/articles/reverse-integer/)
|
||||
|
||||
# Appendix
|
||||
Reference in New Issue
Block a user