前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2017年8月26日

2017年8月26日

作者头像
阿章-python小学生
发布2018-05-18 17:01:19
6410
发布2018-05-18 17:01:19
举报
  1. python2中的cmp(x,0)函数返回1 0 或 -1 在python3中被去除了,如果想得到在python3中 类似的函数可以使用 (x>0)-(x<0),一定要加括号否则结果不一样。
  2. Leetcode问题 Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

代码语言:javascript
复制
Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].

answer:

代码语言:javascript
复制
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)

  1. Leetcode问题 Reverse digits of an integer.
代码语言:javascript
复制
Example1: x = 123, return 321
Example2: x = -123, return -321

click to show spoilers.

Note:
The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.

Answer:

代码语言:javascript
复制
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
  1. 如何更改jupyter notebook的密码?
代码语言:javascript
复制
jupter notebook password
# 之后输入密码即可,该命令会生成一个配置文件在~/.jupyter/jupyter_notebook_config.json
  1. git extensions bug Committingfails:couldnotread log file,Invalidargument。 解释地址: https://github.com/gitextensions/gitextensions/issues/3800 解决方案。找到settings->Advanced->Use Console Emulator for console output in command dialogs 把他disable就可以了。
  2. git在linux上乱码问题解决。 在windows上提交没问题,在linux上显示日志时乱码。这是由于两个系统编码不同所致。可以通过 一下设置来解决(在linux上设置)
代码语言:javascript
复制
设置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即可显示更清楚的日志。

  1. git想checkout远程分支建立对应的本地分支。

比如有个远程分支是foo,想在本地checkout它,命令如下:

代码语言:javascript
复制
git checkout -b foo origin/foo

查看当前所有分支

代码语言:javascript
复制
git branch -va
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 python全栈布道师 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Note:
  • The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档