(x>0)-(x<0)
,一定要加括号否则结果不一样。
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
answer:
class Solution(object):
def twoSum(self, nums, target):
if len(nums) <= 1:
return False
buff_dict = {}
for i in range(len(nums)):
if nums[i] in buff_dict:
return [buff_dict[nums[i]], i]
else:
buff_dict[target - nums[i]] = i
时间复杂度为O(n)
Example1: x = 123, return 321
Example2: x = -123, return -321
click to show spoilers.
Answer:
class Solution(object):
def reverse(self, x):
n = ((x > 0) - (x < 0)) * int(str(abs(x))[::-1])
return n if n.bit_length() < 32 else 0
jupter notebook password
# 之后输入密码即可,该命令会生成一个配置文件在~/.jupyter/jupyter_notebook_config.json
Committingfails:couldnotread log file,Invalidargument
。 解释地址: https://github.com/gitextensions/gitextensions/issues/3800 解决方案。找到settings->Advanced->Use Console Emulator for console output in command dialogs 把他disable就可以了。
设置git 的界面编码:
git config --global gui.encoding utf-8
设置 commit log 提交时使用 utf-8 编码:
git config --global i18n.commitencoding utf-8
使得在 $ git log 时将 utf-8 编码转换成 gbk 编码:
git config --global i18n.logoutputencoding gbk
使得 git log 可以正常显示中文:
export LESSCHARSET=utf-8
这样就可以了。(其实主要是 exportLESSCHARSET=utf-8
在起作用) 显示日志可以使用 git config--globalalias.lg"log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
以后使用git lg即可显示更清楚的日志。
比如有个远程分支是foo,想在本地checkout它,命令如下:
git checkout -b foo origin/foo
查看当前所有分支
git branch -va