This commit is contained in:
d0zingcat
2020-05-25 12:04:01 +08:00
parent 3af6b2d768
commit a17f2f2e42
4 changed files with 83 additions and 2 deletions

View File

@@ -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/) |

View File

@@ -34,3 +34,9 @@ menu = "main"
### iOS
- [Infuse](https://firecore.com/infuse):视频播放
## 网站
### 下载
- [Old version](http://www.oldversion.com):下载软件历史版本

View File

@@ -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 dont 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....`

View 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