大道至简

人生苦短,我用Python.

LeetCode-Alg-112-Path-Sum

LeetCode-Alg-112-Path-Sum

1、题目 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. Note: A leaf is a node with no children. ...

KVM虚拟机qcow2格式硬盘扩容

KVM虚拟机适用命令行对qcow2格式硬盘扩容

1、环境 一台Centos7虚拟机,名称为jae-dev运行在KVM之上,磁盘信息如下,现将磁盘增加100G [xidian@localhost ~]$ df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 26G 8.1G 18G 31% / devtmpfs ...

GitLib配置163邮件服务器

GitLib配置163邮件服务器

修改配置文件 在```/etc/gitlib/gitlib.rb```文件中配置如下: ### Email Settings gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.163.com" gitlab_rails['smtp_port'] = 25 gitlab_rails['smtp_u...

二分法求目标值范围

利用二分法求在非降序数组中距离目标值最近的两个数

要求 给一个没有重复元素的数组和目标值target,求距离该target最近的两个值,返回该距离(绝对值) 使用二分查找求目标值最近距离 定义两个指针left和high,并计算mid=left+(righ-left)/2,循环终止条件为left+1>=righ,循环终止说明目标值落在left和righ指向的两个值之间即nums[left]<=target<=nums[...

LeetCode-Alg-475-heaters

LeetCode-Alg-475-heaters

1、题目 Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses. Now, you are given positions of houses and heaters on a horiz...

Numpy中数组拼接

Numpy中不同数组拼接

多个不同的数组沿着不同的轴拼接在一起 import numpy as np a = np.arange(4).reshape((2, 2)) a array([[0, 1], [2, 3]]) b = np.array([[4, 5],[6, 7]]) b array([[4, 5], [6, 7]]) a和b都是2x2的矩阵 将a和b在垂直方向上合并成4x1矩阵 np...

LeetCode-Alg-441-Arranging-Coins

LeetCode-Alg-441-Arranging-Coins

1、题目 You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be forme...

Numpy中shape为(m,)的是行向量还是列向量

Numpy中shape为(m,)的是行向量还是列向量

1、shape为(m,)的向量是行向量还是列向量 定义一个一维数组 v = np.array([1, 2]) v array([1, 2]) 该数组的shape为 v.shape (2,) 再定义一个数组 z = np.array([[1], [2]]) 该数组的shape为 z.shape (2, 1) 到这里我们可能认为shape为(2,)的数组是个行向量,先不...

LeetCode-Alg-367-Valid-Perfect-Square

LeetCode-Alg-367-Valid-Perfect-Square

1、题目 Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1: Input: 16 Ou...

牛顿-迭代法计算平方根

牛顿-拉弗森方法

牛顿-拉弗森方法 牛顿迭代法又被称为牛顿-拉弗森方法,实际是牛顿、拉弗森各自独立提出来的,该方法提出的思路就是利用切线是曲线的线性逼近这个思想。 多数的方程不存在求根公式,所以求精确根非常困难,甚至是不可能,该方法利用函数 \( f(x) \)的泰勒级数的前面几项来寻找方程\( f(x)=0 \)的根,,牛顿迭代法最大的有点是在方程\( f(x)=0 \)的单根附近具有平方收敛,而且该方...

< script src = " / js / bootstrap.min.js " >