├── .gitignore
├── README.md
├── README_cp.md
├── data_analysis
├── Numpy基础.md
├── main.md
├── 深入浅出统计学笔记上.md
└── 深入浅出统计学笔记下.md
├── dataset
├── US_Crime_Rates_1960_2014.csv
├── appl_1980_2014.csv
├── cars1.csv
├── cars2.csv
├── chipotle.csv
├── drinks.csv
├── euro12.csv
├── iris.csv
└── wind_data.csv
├── django_note
├── URL调度器.md
├── django_code
│ └── mysite
│ │ ├── db.sqlite3
│ │ ├── manage.py
│ │ ├── mysite
│ │ ├── __init__.py
│ │ ├── asgi.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ │ └── polls
│ │ ├── __init__.py
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0002_auto_20201018_1654.py
│ │ └── __init__.py
│ │ ├── models.py
│ │ ├── templates
│ │ └── polls
│ │ │ ├── detail.html
│ │ │ ├── index.html
│ │ │ └── result.html
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
├── main.md
├── 快捷函数.md
├── 查询.md
├── 模型.md
├── 编写一个投票web站点.md
├── 编写视图.md
└── 聚合.md
├── leetcode_array
├── 较大分组的位置.md
├── 1比特与2比特字符.md
├── main.md
├── 三个数的最大乘积.md
├── 三数之和.md
├── 两数之和II.md
├── 买卖股票的最佳时机.md
├── 买卖股票的最佳时机II.md
├── 删除排序数组中的重复项.md
├── 加一.md
├── 单调数列.md
├── 反转字符串.md
├── 反转字符串II.md
├── 合并两个有序数组.md
├── 四数之和.md
├── 图片平滑器.md
├── 多数元素.md
├── 子数组最大平均数I.md
├── 存在重复元素.md
├── 存在重复元素II.md
├── 寻找数组的中心索引.md
├── 左旋转字符串.md
├── 托普利茨矩阵.md
├── 找到所有数组中消失的数字.md
├── 按奇偶排序数组.md
├── 搜索插入位置.md
├── 数组中的K-diff数对.md
├── 数组拆分I.md
├── 数组的度.md
├── 斐波那契数.md
├── 旋转数组.md
├── 替换空格.md
├── 最大子序和.md
├── 最大连续1的个数.md
├── 最短无序连续子数组.md
├── 最长连续递增序列.md
├── 杨辉三角.md
├── 杨辉三角II.md
├── 矩阵中的幻方.md
├── 种花问题.md
├── 移动零.md
├── 移除元素.md
├── 第三大的数.md
├── 缺失数字.md
├── 翻转图像.md
├── 翻转字符串里的单词.md
├── 至少是其他数字两倍的最大数.md
├── 螺旋矩阵2.md
├── 转置矩阵.md
├── 重塑矩阵.md
├── 长度最小的子数组.md
└── 非递减数列.md
├── leetcode_hash
├── main.md
├── 两个数组的交集.md
├── 两数之和.md
├── 四数相加II.md
├── 快乐数.md
├── 有效的字母异位词.md
└── 赎金信.md
├── leetcode_linked_list
├── main.md
├── 二进制链表转整数.md
├── 删除排序链表中的重复元素.md
├── 删除链表中的节点.md
├── 删除链表的倒数第N个结点.md
├── 反转链表.md
├── 合并两个有序链表.md
├── 回文链表.md
├── 环形链表.md
├── 环形链表II.md
├── 相交链表.md
├── 移除链表元素.md
├── 设计链表.md
└── 链表的中间结点.md
├── leetcode_others
└── main.md
├── leetcode_stack
├── main.md
├── 下一个更大元素1.md
├── 删除字符串中的所有相邻重复项.md
├── 删除最外层的括号.md
├── 前K个高频元素.md
├── 整理字符串.md
├── 文件夹操作日志搜集器.md
├── 最小栈.md
├── 有效的括号.md
├── 棒球比赛.md
├── 比较含退格的字符串.md
├── 滑动窗口最大值.md
├── 用栈实现队列.md
├── 用栈操作构建数组.md
├── 用队列实现栈.md
└── 逆波兰表达式求值.md
├── leetcode_tree
├── main.md
├── 二叉树的中序遍历.md
├── 二叉树的前序遍历.md
├── 二叉树的后序遍历.md
├── 二叉树的层序遍历.md
├── 二叉树的层次遍历II.md
├── 二叉树的所有路径.md
├── 二叉树的最大深度.md
├── 二叉树的最小深度.md
├── 反转二叉树.md
├── 另一个树的子树.md
├── 完全二叉树的节点个数.md
├── 对称二叉树.md
├── 将有序数组转换为二叉搜索树.md
├── 左叶子之和.md
├── 平衡二叉树.md
├── 找树左下角的值.md
├── 相同的树.md
└── 路径总和.md
├── linux
├── Linux常用操作命令.md
├── Linux常用系统工作命令.md
├── Linux文件压缩与打包.md
├── Linux文件权限.md
├── Linux文件目录管理.md
├── Linux文件目录管理命令.md
├── Linux文件系统.md
├── Linux目录切换与文本编辑.md
├── Linux系统状态监测命令.md
├── Shell位置参数与特殊变量.md
├── Shell函数.md
├── Shell变量.md
├── Shell字符串.md
├── Shell数学计算.md
├── Shell数组.md
├── casein语句.md
├── centos7安装nginx.md
├── for循环.md
├── if语句.md
├── main.md
├── nginx基本配置与参数说明.md
├── nignx_install
│ ├── nginx-1.18.0.tar.gz
│ ├── openssl-1.1.1g.tar.gz
│ ├── pcre-8.44.tar.gz
│ └── zlib-1.2.11.tar.gz
├── sed命令与awk命令.md
├── shell语法.md
├── test命令和[[]].md
├── tmux常用操作命令.md
├── vim编辑器与shell命令脚本.md
├── vim编辑器基本操作.md
├── while语句.md
├── 常用shell脚本.md
├── 数据流重定向与管线命令.md
├── 正则表达式.md
└── 管道符重定向与环境变量.md
├── network_protocol
├── HTTPS原理.md
├── HTTP概念.md
├── IP协议.md
├── IP数据报的发送和转发过程.md
├── MAC_IP_ARP.md
├── TCPIP总结.md
├── TCPUDP协议.md
├── TCP可靠传输的实现.md
├── TCP的拥塞控制.md
├── TCP的流量控制.md
├── TCP超时重传时间的选择.md
├── TCP连接的建立与释放.md
├── TCP首部.md
├── http首部字段.md
├── main.md
├── 二层交换机.md
├── 总结.md
├── 数据链路.md
├── 物理层与数据链路层.md
├── 状态码网关代理隧道.md
├── 电路交换与分组交换.md
├── 网络基础知识.md
├── 网络层.md
├── 计算机网络分类.md
├── 计算机网络的体系结构.md
├── 计算机网络的性能指标.md
└── 运输层.md
├── others
├── ZeroMQ基础.md
├── kafka基本概念.md
├── main.md
├── redis基础操作.md
└── redis基础理论.md
├── pic
├── asyncio1.png
├── bibao.png
├── conditi.png
├── data_analysis
│ ├── 11.png
│ ├── 112.png
│ ├── 2.png
│ ├── 20180204151140.png
│ ├── 20180204152134.png
│ ├── 20180204152456.png
│ ├── 2EV.png
│ ├── bop.png
│ ├── jihe.png
│ ├── jihep.png
│ ├── jihep2.png
│ ├── jihep3.png
│ ├── jihevar.png
│ ├── pailie.png
│ ├── shijian.png
│ └── zuhe.png
├── diguistack.jpg
├── django_note
│ ├── django1.jpg
│ └── django2.jpg
├── gitdoc
│ ├── 1_1.png
│ ├── 1_2.png
│ ├── 1_3.png
│ ├── 2_1.png
│ ├── 2_2.png
│ ├── 2_3.png
│ ├── 2_4.png
│ ├── 2_5.png
│ ├── 2_6.png
│ ├── 2_7.png
│ ├── 2_8.png
│ ├── 2_9.png
│ ├── 3_1_1.png
│ ├── 3_1_2.png
│ ├── 3_1_3.png
│ ├── 3_1_4.png
│ ├── 3_1_5.png
│ ├── 3_1_6.png
│ ├── 3_1_7.png
│ ├── 3_2_1.png
│ ├── 3_2_2.png
│ ├── 3_2_3.png
│ ├── 3_2_4.png
│ └── gitbase.png
├── hashtable.jpg
├── htiao.jpg
├── jiaocuotiao.jpg
├── leetcode_array
│ ├── 05_1.gif
│ ├── 15_1.gif
│ ├── 209_1.gif
│ ├── 27_1.png
│ ├── 27_2.png
│ ├── 344_1.png
│ ├── 35_1.png
│ ├── 35_2.png
│ ├── 35_3.png
│ ├── 35_4.png
│ ├── 35_5.png
│ ├── 35_6.png
│ ├── 59_1.png
│ └── yanghuisanjiao.png
├── leetcode_hash
│ ├── 202_1.png
│ └── 202_2.png
├── leetcode_linked_list
│ ├── 142_1.png
│ ├── 142_2.png
│ ├── 19_1.gif
│ ├── 19_1.png
│ ├── 19_2.png
│ ├── 203_1.png
│ ├── 203_2.png
│ ├── 206_1.gif
│ ├── linkedlist2.png
│ └── linkelist1.png
├── leetcode_stack
│ ├── 1047_1.gif
│ ├── 150_1.gif
│ ├── 225_1.gif
│ ├── 232_1.gif
│ ├── 239_1.gif
│ ├── 239_1.png
│ ├── duilie.png
│ └── stack.png
├── leetcode_tree
│ ├── 101_1.png
│ ├── 112_1.gif
│ ├── 112_1.jpg
│ ├── 144_1.gif
│ ├── 226_1.gif
│ ├── 226_1.png
│ ├── 257_1.gif
│ ├── 94_1.gif
│ ├── balance_1.jpg
│ ├── bianlitree.png
│ ├── ex_depth.jpg
│ ├── manerchashu.png
│ ├── paixutree.png
│ └── wanquantree.png
├── linux
│ ├── fs1.png
│ ├── fs2.png
│ ├── linuxcmd_head.png
│ ├── linuxcmd_locate.png
│ ├── linuxcmd_ls.png
│ ├── linuxcmd_rm.png
│ ├── linuxcmd_stat.png
│ ├── linuxqx.png
│ ├── linuxqx2.png
│ ├── shell1.png
│ └── tar1.png
├── lock.png
├── maoyan.png
├── namedtuple.jpg
├── network_protocol
│ ├── IPB.png
│ ├── IPC.png
│ ├── IPfenlei.png
│ ├── IPjump.png
│ ├── IProute.png
│ ├── L2MAC.png
│ ├── https_1.png
│ ├── https_2.png
│ ├── https_3.png
│ ├── https_4.png
│ ├── https_5.png
│ ├── https_6.png
│ ├── ipmac.png
│ ├── ipmac2.png
│ ├── ipzhuanfa.png
│ ├── ipzhuanfa2.png
│ ├── ipzhuanfa3.png
│ ├── ipzhuanfa4.png
│ ├── shuyu1.png
│ ├── tcphead.png
│ ├── tcphead2.png
│ ├── tcphead3.png
│ ├── tcpip.png
│ ├── tcplianjie1.png
│ ├── tcplianjie2.png
│ ├── tcplianjie3.png
│ ├── tcplianjie4.png
│ ├── tcpliuliangkongzhi.png
│ ├── tcpliuliangkongzhi2.png
│ ├── tcpliuliangkongzhi3.png
│ ├── tcprtt.png
│ ├── tcprtt2.png
│ ├── tcprtt3.png
│ ├── tcpstatus.png
│ ├── tcptrs1.png
│ ├── tcptrs2.png
│ ├── tcptrs3.png
│ ├── tcptrs4.png
│ ├── tcptrs5.png
│ ├── tcptrs6.png
│ ├── tcptrs7.png
│ ├── tcpudpport.png
│ ├── tcpys1.png
│ ├── tcpys3.png
│ ├── tcpys4.png
│ ├── tcpys5.png
│ ├── tongxinshili.png
│ ├── ziwangyanma1.png
│ └── ziwangyanma2.png
├── nginxhttps.jpg
├── nginxproxy1.png
├── nginxproxy2.png
├── nginxproxy5.png
├── nginxproxy6.png
├── nolock.png
├── others
│ ├── chapter1_1zmq.png
│ ├── chapter1_4zmq.png
│ ├── chapter1_5zmq.png
│ ├── kafkafabu.png
│ ├── kafkahanyi.png
│ ├── kafkaleader.png
│ ├── kafkaqueue.png
│ ├── redis_1.jpg
│ ├── zmq_sink.png
│ └── zmq_ventilator.png
├── pie.png
├── python_advance
│ ├── download.png
│ ├── gc_1.png
│ ├── join.png
│ ├── setDaemonTrue.png
│ ├── tcp_client.png
│ ├── tcp_server.png
│ └── upload.png
├── python_basic
│ ├── tuple2.png
│ └── tuple3.png
├── redisqueue.png
├── roominfo1.png
├── roominfo2.png
├── roominfo3.png
├── roominfo4.png
├── scrapy1.png
├── scrapy2.png
├── scrapy3.png
├── shunqi1.png
├── shunqi2.png
├── shunqi3.png
├── shunqi4.png
├── spiders
│ ├── proxypool.png
│ ├── zhihu1.png
│ ├── zhihu2.png
│ ├── zhihu3.png
│ ├── zhihu4.png
│ ├── zhihu5.png
│ └── zhihu7.png
├── stack.jpg
├── taobaores1.png
├── taobaores2.png
├── tcpconn.png
├── threadin.png
├── toutiaopic.png
├── tu.jpg
├── tuple2.png
├── vtiao.jpg
├── wangzhan.png
├── wangzhan1.png
├── wangzhan2.png
├── wangzhan3.png
├── weibo1.png
├── weibo2.png
├── weibo3.png
├── weibo4.jpg
├── weibo5.jpg
├── weixinrequests.png
├── weixinspider2.png
├── xiecheng.jpg
├── xiecheng.png
├── yzm.png
└── zhihu6.png
├── python_advance
├── Git基础.md
├── MongoDB存储图片.md
├── Python上下文管理器与with语句.md
├── Python中的下划线.md
├── Python中的多线程.md
├── Python中的多进程.md
├── Python之AES加密解密.md
├── Python垃圾回收机制.md
├── Python实现TFTP文件传输.md
├── Python实现单例模式.md
├── Python连接数据库.md
├── concurrentfutures模块.md
├── main.md
├── opencv-python基础.md
├── python中的协程.md
├── socket网络编程.md
├── 位置参数默认参数可变参数关键字参数.md
├── 变量的作用域.md
├── 可迭代对象迭代器生成器.md
├── 命名空间与作用域.md
├── 模块和包.md
├── 类实例静态方法.md
├── 装饰器.md
├── 进程与线程概念.md
└── 通用日志模块.md
├── python_basic
├── Excel文件处理.md
├── Python函数参数的传递机制.md
├── Python在内存中读写数据.md
├── Python标准数据类型.md
├── Python读取大文本文件.md
├── XML文件处理.md
├── is.md
├── json文件处理.md
├── main.md
├── new和init方法.md
├── python异常处理机制.md
├── utf8BOM文件处理.md
├── 保护变量的访问与设置.md
├── 关于tuple.md
├── 列表推导式.md
├── 创建临时文件.md
├── 字节串与十六进制转换.md
├── 序列化与反序列化.md
├── 总结.md
├── 文件目录事件监控.md
├── 文件目录扫描.md
├── 文件路径处理.md
├── 时间格式转换.md
├── 深拷贝与浅拷贝.md
├── 猴子补丁.md
├── 等分字符串.md
├── 网络字节序与主机字节序转换.md
├── 解析命令行参数getopt.md
├── 读取配置文件configparser.md
├── 车牌格式校验.md
└── 集合删除元素.md
├── spiders
├── Python爬虫xpath解析.md
├── Python爬虫之BeautifulSoup.md
├── Python爬虫之requests库.md
├── Python爬虫之selenium自动化.md
├── Python爬虫之uiautomator2常用操作.md
├── Python爬虫之构建自己的代理IP池.md
├── Python爬虫之知乎钓鱼贴图片爬取.md
├── agent_pool
│ ├── Crawler.py
│ ├── RedisClient.py
│ ├── WebAPI_to_get_proxy.py
│ └── agent_pool.py
├── dazhongdianping
│ ├── 1.html
│ ├── 2.html
│ ├── decode_str.py
│ ├── decode_str.txt
│ ├── dianpingspider.py
│ └── test.py
├── main.md
├── python爬虫之一尘论坛发帖数据爬取.md
├── python爬虫之网易云音乐.md
└── 概念.md
└── studynotes
├── Linux-vim编辑器.md
├── Linux命令.md
├── Linux常用操作命令.md
├── Linux文件权限.md
├── Python中的单下划线与双下划线.md
├── Python之AES加密解密.md
├── Python之namedtuple对象.md
├── Python之代码pythonic几种写法.md
├── Python之利用MongoDB存储图片.md
├── Python之协程.md
├── Python之多线程.md
├── Python之多进程.md
├── Python之异步IO--asyncio用法.md
├── Python之异步http库--aiohttp.md
├── Python之装饰器.md
├── Python利用socket实现简单http server.md
├── Python十进制、十六进制、字节串、字符串转换.md
├── Python变量作用域与闭包.md
├── Python基础习题.md
├── Python基础总结一.md
├── Python基础总结二.md
├── Python如何在两个py文件中共享同一个变量.md
├── Python学习之jieba库(分词).md
├── Python实现TFTP文件传输.md
├── Python常用小知识点(更新ing……).md
├── Python数据分析学习一--numpy.md
├── Python数据分析学习七--groupby分组.md
├── Python数据分析学习三--数据加载.md
├── Python数据分析学习二--pandas库.md
├── Python数据分析学习五--数据转换、过滤清理.md
├── Python数据分析学习六--字符串操作.md
├── Python数据分析学习四--合并数据集.md
├── Python爬虫--scrapy爬虫框架入门.md
├── Python爬虫--selenium基础操作.md
├── Python爬虫--selenium爬取淘宝商品信息.md
├── Python爬虫--xpath解析.md
├── Python爬虫--代理池维护.md
├── Python爬虫--利用代理池系统爬取微信公众号文章.md
├── Python爬虫--头条街拍图片爬取.md
├── Python爬虫--武汉15个地区9万条二手房数据.md
├── Python爬虫--爬取微博指定用户主页下的所有图片.md
├── Python爬虫--爬取网站验证码.md
├── Python爬虫--猫眼电影top100基本信息.md
├── Python爬虫--知乎钓鱼贴3万多张漂亮小姐姐照片.md
├── Python爬虫--设置代理.md
├── Python爬虫--顺企网企业信息爬取.md
├── Python爬虫之BeautifulSoup.md
├── Python爬虫之Requests库.md
├── Python简单处理csv,json,xml,Excel文件.md
├── Python网络编程之socketserver.md
├── Python进程、线程、协程概念.md
├── Python连接数据库操作.md
├── Python通用日志模块配置.md
├── Redis基础操作.md
├── ZeroMQ基础.md
├── git文档.md
├── matplotlib绘制简单的条形图.md
├── matplotlib绘制饼状图.md
├── nginx+flask+gunicorn部署.md
├── pandas--数据集合并与风速数据统计.md
├── pandas--时间序列和数据删除.md
├── pandas分析Chipotle快餐数据.md
├── pandas分析之欧洲杯数据.md
├── pandas分析酒类消费数据与美国犯罪数据.md
├── shell语法.md
├── vue.js基础.md
├── 《图解HTTP》—http首部字段总结.md
├── 《图解HTTP》学习—状态码、网关、代理、隧道.md
├── 《图解HTTP》学习笔记之协议.md
├── 《深入浅出统计学》笔记上.md
├── 《深入浅出统计学》笔记下.md
├── 一、kafka是什么.md
├── 一、网络基础知识.md
├── 三、IP协议.md
├── 二、数据链路.md
├── 二分查找、选择排序、递归.md
├── 四、TCP与UDP.md
└── 快速排序、哈希表、图、广度优先搜索算法.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | __pycache__/
3 | venv/
4 | .env
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | |分类|简介|
2 | |-|-|
3 | |[Python基础](./python_basic/main.md)|python常用小知识点,目录监控,文件处理,日志等......|
4 | |[Python进阶](./python_advance/main.md)|python网络编程socket,多线程,多进程,装饰器,面向对象等......|
5 | |[Linux相关](./linux/main.md)|linux常用操作命令,vim,环境安装部署等......|
6 | |[Python数据分析](./data_analysis/main.md)|《深入浅出统计学》,numpy,pandas基础概念及练习等......|
7 | |[Python爬虫](./spiders/main.md)|python爬虫基础库requests,beautifulsoup,xpath,selenium,代理池,部分网站爬虫等......|
8 | |[计算机网络基础](./network_protocol/main.md)|网络基础知识,tcp/ip协议与http协议等......|
9 | |[LeetCode-数组](./leetcode_array/main.md)|leetcode数组类,字符串类算法练习|
10 | |[LeetCode-链表](./leetcode_linked_list/main.md)|leetcode链表类算法练习|
11 | |[LeetCode-哈希表](./leetcode_hash/main.md)|leetcode哈希表类算法练习|
12 | |[LeetCode-栈+队列](./leetcode_stack/main.md)|leetcode栈+队列类算法练习|
13 | |[LeetCode-二叉树](./leetcode_tree/main.md)|leetcode二叉树类算法练习|
14 | |[LeetCode-其他](./leetcode_others/main.md)|leetcode其他分类算法练习|
15 | |[Django学习](./django_note/main.md)|Django学习笔记。|
16 | |[其他](./others/main.md)|redis,kafka,ZeroMQ等|
17 |
--------------------------------------------------------------------------------
/data_analysis/Numpy基础.md:
--------------------------------------------------------------------------------
1 | # Numpy基础
2 |
--------------------------------------------------------------------------------
/data_analysis/main.md:
--------------------------------------------------------------------------------
1 | ## 数据分析
2 | 1. [《深入浅出统计学》笔记上](深入浅出统计学笔记上.md)
3 | 2. [《深入浅出统计学》笔记下](深入浅出统计学笔记下.md)
4 | 3. [Python Numpy基础](Numpy基础.md)
5 |
--------------------------------------------------------------------------------
/data_analysis/深入浅出统计学笔记下.md:
--------------------------------------------------------------------------------
1 | ## 第十章:抽取样本
2 | 样本:从总体中选取的相对较小的集合,可用于做出关于总体本身的结论。
3 | 简单随机抽样:随机选择抽样单位并形成样本,包括重复抽样和不重复抽样。(具体方式包括抽签或使用随机编号生成器)
4 | 分层抽样:将总体划分为几个组或几个层,每一层尽可能与其他层不一样(比如糖果按颜色分层),分层好之后,对每一层执行简单随机抽样。
5 | 整群抽样:将总体划分为几个群,其中每个群尽量与其他群相似,随后通过简单随机抽样选取群,再接着对群中的对象进行抽样。
6 | 系统抽样:选取一个数字K,然后每到第K个抽样单位就抽样一次。
7 | ## 第十一章:总体和样本的估计
8 | ### 通过样本估计总体
9 | 统计量太大时,我们无法通过总体计算出总体的均值μ,或方差σ²时,而只能通过样本数据估计这些参数。**一个总体参数的点估计量(由样本数据得出,是对总体参数的估计)就是可用于估计总体参数数值的某个函数
10 | 或者算式,比如我们能用样本均值û 估计总体均值μ,因此样本均值就是总体均值的点估计量**
11 |
12 | 
13 |
14 | ### 通过总体估计样本(样本比例,样本均值)
15 | 比例的抽样分布:从同一个总体(X~B(n,p))中取得的所有大小为n的可能样本,由这些样本的比例形成的分布,就是“比例的抽样分布”,用Ps代表样本比例随机变量。
16 |
17 | **E(Ps)=p, Var(Ps)=pq/n 如果n>30,则Ps符合正态分布:Ps~N(p,pq/n),连续性修正时+1/2n 或 -1/2n**
18 |
19 | 均值的抽样分布:利用从所有可能样本得出的所有样本均值形成一个分布,叫做“均值的抽样分布”。
20 |
21 | 
22 |
23 | 中心极限定理:如果从一个非正态总体X中取出一个样本,且样本很大,则样本均值的分布近似为正态分布。如果总体的均值为μ,方差为σ²,且样本数很大,则样本均值的分布X'~N(μ,σ²/n)
24 |
25 | **中心极限定理应用二项分布**X~B(n,p),则X'~N(np,pq)
26 |
27 | **中心极限定理应用泊松分布**X~Po(λ),则X'~N(λ,λ/n)
28 | ## 第十二章:置信区间
29 | 求置信区间步骤:
30 | 1. 首先选择用于构建置信区间的总体统计量。(比如均值)
31 | 2. 求出统计量的抽样分布。
32 | 3. 确定你所需要的置信水平(比如95%)。
33 | 4. 求出置信区间的上下限(a,b)
34 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/django_note/django_code/mysite/db.sqlite3
--------------------------------------------------------------------------------
/django_note/django_code/mysite/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | """Run administrative tasks."""
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
10 | try:
11 | from django.core.management import execute_from_command_line
12 | except ImportError as exc:
13 | raise ImportError(
14 | "Couldn't import Django. Are you sure it's installed and "
15 | "available on your PYTHONPATH environment variable? Did you "
16 | "forget to activate a virtual environment?"
17 | ) from exc
18 | execute_from_command_line(sys.argv)
19 |
20 |
21 | if __name__ == '__main__':
22 | main()
23 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/mysite/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/django_note/django_code/mysite/mysite/__init__.py
--------------------------------------------------------------------------------
/django_note/django_code/mysite/mysite/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for mysite project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/mysite/urls.py:
--------------------------------------------------------------------------------
1 | """mysite URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/3.1/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.urls import include, path
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 | """
16 | from django.contrib import admin
17 | from django.urls import path, include
18 |
19 | urlpatterns = [
20 | path('admin/', admin.site.urls),
21 | path('polls/', include('polls.urls')),
22 | ]
23 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/mysite/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for mysite project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/django_note/django_code/mysite/polls/__init__.py
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 | from .models import Question, Choice
3 |
4 | admin.site.register(Question)
5 | admin.site.register(Choice)
6 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class PollsConfig(AppConfig):
5 | name = 'polls'
6 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.1 on 2020-10-18 08:43
2 |
3 | from django.db import migrations, models
4 | import django.db.models.deletion
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | initial = True
10 |
11 | dependencies = [
12 | ]
13 |
14 | operations = [
15 | migrations.CreateModel(
16 | name='Question',
17 | fields=[
18 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19 | ('questiong_text', models.CharField(max_length=200)),
20 | ('pub_date', models.DateTimeField()),
21 | ],
22 | ),
23 | migrations.CreateModel(
24 | name='Choice',
25 | fields=[
26 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
27 | ('choice_text', models.CharField(max_length=200)),
28 | ('votes', models.IntegerField(default=0)),
29 | ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.question')),
30 | ],
31 | ),
32 | ]
33 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/migrations/0002_auto_20201018_1654.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.1 on 2020-10-18 08:54
2 |
3 | from django.db import migrations
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('polls', '0001_initial'),
10 | ]
11 |
12 | operations = [
13 | migrations.RenameField(
14 | model_name='question',
15 | old_name='questiong_text',
16 | new_name='question_text',
17 | ),
18 | ]
19 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/django_note/django_code/mysite/polls/migrations/__init__.py
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 | from django.utils import timezone
3 | import datetime
4 |
5 |
6 | class Question(models.Model):
7 | question_text = models.CharField(max_length=200)
8 | pub_date = models.DateTimeField()
9 |
10 | def __str__(self):
11 | return self.question_text
12 |
13 | def was_published_recently(self):
14 | return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
15 |
16 |
17 | class Choice(models.Model):
18 | question = models.ForeignKey(Question, on_delete=models.CASCADE)
19 | choice_text = models.CharField(max_length=200)
20 | votes = models.IntegerField(default=0)
21 |
22 | def __str__(self):
23 | return self.choice_text
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/templates/polls/detail.html:
--------------------------------------------------------------------------------
1 |
{{ question.question_text }}
2 |
3 | {% if error_message %}{{ error_message }}
{% endif %}
4 |
5 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/templates/polls/index.html:
--------------------------------------------------------------------------------
1 | {% if latest_question_list %}
2 |
7 | {% else %}
8 | No polls are available.
9 | {% endif %}
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/templates/polls/result.html:
--------------------------------------------------------------------------------
1 | {{ question.question_text }}
2 |
3 |
4 | {% for choice in question.choice_set.all %}
5 | - {{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}
6 | {% endfor %}
7 |
8 |
9 | Vote again?
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/django_note/django_code/mysite/polls/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 | from . import views
3 |
4 | app_name = 'polls'
5 | urlpatterns = [
6 | path('', views.index, name='index'),
7 | path('/', views.detail, name='detail'),
8 | path('/result/', views.result, name='result'),
9 | path('/vote/', views.vote, name='vote'),
10 | ]
--------------------------------------------------------------------------------
/django_note/main.md:
--------------------------------------------------------------------------------
1 | ## Django学习笔记
2 | 1. [Django入门-编写一个投票web站点](编写一个投票web站点.md)
3 | #### 模型和数据库
4 | 2. [Django入门-模型](模型.md)
5 | 3. [Django入门-查询](查询.md)
6 | 4. [Django入门-聚合](聚合.md)
7 | #### 处理HTTP请求
8 | 5. [Django入门-URL调度器](URL调度器.md)
9 | 6. [Django入门-编写视图](编写视图.md)
10 | 7. [Django入门-快捷函数](快捷函数.md)
11 |
--------------------------------------------------------------------------------
/leetcode_array/ 较大分组的位置.md:
--------------------------------------------------------------------------------
1 | 在一个由小写字母构成的字符串 S 中,包含由一些连续的相同字符所构成的分组。
2 | 例如,在字符串 S = "abbxxxxzyy" 中,就含有 "a", "bb", "xxxx", "z" 和 "yy" 这样的一些分组。
3 | 我们称所有包含大于或等于三个连续字符的分组为较大分组。找到每一个较大分组的起始和终止位置。
4 | 最终结果按照字典顺序输出。
5 | 示例:
6 | ```python
7 | 输入: "abbxxxxzzy"
8 | 输出: [[3,6]]
9 | 解释: "xxxx" 是一个起始于 3 且终止于 6 的较大分组。
10 |
11 | 输入: "abcdddeeeeaabbbcd"
12 | 输出: [[3,5],[6,9],[12,14]]
13 | ```
14 |
15 | #### 分析:
16 | * 遍历数组
17 | * current_s 记录当前计数的字母
18 | * current_s_count 记录当前计数字母的数量
19 | * 注意遍历结束后 current_s_count >=3的情况
20 |
21 | 代码:
22 | ```python
23 | def largeGroupPositions(S):
24 | res = []
25 | current_s = None
26 | current_s_count = 0
27 | for index, s in enumerate(S):
28 | if not current_s:
29 | current_s = s
30 | current_s_count += 1
31 | else:
32 | if current_s == s:
33 | current_s_count += 1
34 | else:
35 | if current_s_count >= 3:
36 | res.append([index-current_s_count, index-1])
37 | current_s = s
38 | current_s_count = 1
39 |
40 | # 遍历结束后的情况
41 | if current_s_count >= 3:
42 | res.append([len(S) - current_s_count, len(S) - 1])
43 | ```
44 |
--------------------------------------------------------------------------------
/leetcode_array/1比特与2比特字符.md:
--------------------------------------------------------------------------------
1 | 有两种特殊字符。第一种字符可以用一比特0来表示。第二种字符可以用两比特(10 或 11)来表示。
2 |
3 | 现给一个由若干比特组成的字符串。问最后一个字符是否必定为一个一比特字符。给定的字符串总是由0结束。
4 | 示例:
5 | ```python
6 | 输入:
7 | bits = [1, 0, 0]
8 | 输出: True
9 | 解释:
10 | 唯一的编码方式是一个两比特字符和一个一比特字符。
11 | 所以最后一个字符是一比特字符。
12 |
13 | 输入:
14 | bits = [1, 1, 1, 0]
15 | 输出: False
16 | 解释:
17 | 唯一的编码方式是两比特字符和两比特字符。
18 | 所以最后一个字符不是一比特字符。
19 | ```
20 |
21 | #### 分析:
22 | * 从左向右扫描数组
23 | * 如果元素是1,说明是两比特字符,向后跳两步
24 | * 如果元素是0,说明是一比特字符,向后跳一步
25 | * 如果最终落在了 bits.length−1 的位置,那么说明最后一位一定是一比特字符。
26 |
27 | ```python
28 | class Solution:
29 | def isOneBitCharacter(self, bits: List[int]) -> bool:
30 | i = 0
31 | while i < len(bits) - 1:
32 | if bits[i] == 1:
33 | # 跳两步
34 | i += 2
35 | elif bits[i] == 0:
36 | # 跳一步
37 | i += 1
38 | return i == len(bits) - 1
39 | ```
40 |
--------------------------------------------------------------------------------
/leetcode_array/三个数的最大乘积.md:
--------------------------------------------------------------------------------
1 | 给定一个整型数组,在数组中找出由三个数组成的最大乘积,并输出这个乘积。
2 | 示例:
3 | ```python
4 | 输入: [1,2,3]
5 | 输出: 6
6 | ```
7 | #### 方法一:排序
8 | 对数组进行升序排序后:
9 | 如果没有负数或者只有一个负数,那一定是最后三位数相乘最大
10 | 如果有两个以上负数,考虑负负得正,需要比较最后三个数的乘积,与前两个数的乘积*最后一位正数
11 |
12 | ```python
13 | def maximumProduct(nums):
14 | if len(nums) == 3:
15 | return nums[0] * nums[1] * nums[2]
16 | nums.sort()
17 | max_1 = nums[-1] * nums[-2] * nums[-3]
18 | max_2 = nums[0] * nums[1] * nums[-1]
19 |
20 | return max(max_1, max_2)
21 | ```
22 | #### 方法二:
23 | 通过方法一分析可以看出,实际上只需要找到最小的两个数,和最大的三个数,就可以了。
24 | ```python
25 | def maximumProduct(nums):
26 | max_1, max_2, max_3 = float('-inf'), float('-inf'), float('-inf')
27 | min_1, min_2 = float('inf'), float('inf')
28 | for item in nums:
29 | if item <= min_1:
30 | # 注意赋值顺序
31 | min_2 = min_1
32 | min_1 = item
33 | elif min_1 < item < min_2:
34 | min_2 = item
35 |
36 | if item >= max_1:
37 | max_3 = max_2
38 | max_2 = max_1
39 | max_1 = item
40 | elif item >= max_2:
41 | max_3 = max_2
42 | max_2 = item
43 | elif item > max_3:
44 | max_3 = item
45 | mult_1 = max_1 * max_2 * max_3
46 | mult_2 = min_1 * min_2 * max_1
47 | return max(mult_1, mult_2)
48 | ```
49 |
--------------------------------------------------------------------------------
/leetcode_array/两数之和II.md:
--------------------------------------------------------------------------------
1 | ## 两数之和II
2 | 给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数。
3 | 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2。
4 | 示例:
5 | ```python
6 | 输入: numbers = [2, 7, 11, 15], target = 9
7 | 输出: [1,2]
8 | 解释: 2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。
9 | ```
10 | #### 方法一:哈希表,时间复杂度O(n),空间复杂度O(n)
11 | ```python
12 | def twoSum(numbers, target):
13 | num_dict = {}
14 | for i, item in enumerate(numbers):
15 | other = target - item
16 | if other not in num_dict:
17 | num_dict[item] = i
18 | continue
19 | else:
20 | return [num_dict[other]+1, i+1]
21 | return []
22 | ```
23 |
24 | #### 方法二:利用两个指针,同时利用数组已经排序的这个特点
25 | * 一个指针指向头部,一个指针指向尾部
26 | * 如果和大于目标值,尾部的指针向前运动
27 | * 如果和小于目标值,头部指针向后运动
28 |
29 | ```python
30 | def twoSum(numbers, target):
31 | left_index = 0
32 | right_index = len(numbers)-1
33 | while left_index < right_index:
34 | if numbers[left_index] + numbers[right_index] > target:
35 | right_index -= 1
36 | elif numbers[left_index] + numbers[right_index] < target:
37 | left_index += 1
38 | else:
39 | return [left_index+1, right_index+1]
40 | return []
41 | ```
42 |
--------------------------------------------------------------------------------
/leetcode_array/买卖股票的最佳时机.md:
--------------------------------------------------------------------------------
1 | ## 买卖股票的最佳时机
2 | 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。
3 | 如果你最多只允许完成一笔交易(即买入和卖出一支股票一次),设计一个算法来计算你所能获取的最大利润。
4 | 示例:
5 |
6 | ```python
7 | 输入: [7,1,5,3,6,4]
8 | 输出: 5
9 | 解释: 在第2天(股票价格=1)的时候买入,在第5天(股票价格=6)的时候卖出,最大利润=6-1= 5。
10 | 注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入前卖出股票。
11 | ```
12 | #### 暴力法 时间复杂度O(n2),会超出时间限制:
13 | * 找出给定数组中两个数字之间的最大差值(即,最大利润)
14 | * 第二个数字(卖出价格)必须大于第一个数字(买入价格)。
15 | ```python
16 | def maxProfit(prices):
17 | max_profit = 0
18 | for i in range(0, len(prices)):
19 | for j in range(i+1, len(prices)):
20 | max_profit = max(prices[j]-prices[i], max_profit)
21 | return max_profit
22 | ```
23 | #### 方法二:一次遍历,同时记录最小值与最大利润
24 | * 记录历史股票最低价格,这个价格是相对于当前遍历而言,遍历没结束,不一定是列表最小值。
25 | * 记录当前天数的股票价格与历史最低价格的差值,来记录最大利润。
26 |
27 | ```python
28 | def maxProfit(prices):
29 | if not prices:
30 | return 0
31 | min_price = prices[0]
32 | max_profit = 0
33 | for price in prices[1:]:
34 | # 纪录最小价格
35 | if price < min_price:
36 | min_price = price
37 | # 记录最大利润
38 | if price - min_price > max_profit:
39 | max_profit = price - min_price
40 | return max_profit
41 | ```
42 |
--------------------------------------------------------------------------------
/leetcode_array/买卖股票的最佳时机II.md:
--------------------------------------------------------------------------------
1 | ## 买卖股票的最佳时机 II
2 | 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。
3 | 设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。
4 | 示例:
5 | ```python
6 | 输入: [7,1,5,3,6,4]
7 | 输出: 7
8 | 解释: 在第2天(股票价格=1)的时候买入,在第3天(股票价格=5)的时候卖出,
9 | 这笔交易所能获得利润=5-1=4 ,随后,在第 4 天(股票价格 = 3)的时候买入,
10 | 在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6-3 = 3 。
11 | ```
12 |
13 | 分析:
14 |
15 | 如果是[1,2,3,4,5],最大利润=5-1=(2-1)+(3-2)+(4-3)+(5-4)
16 |
17 | 只要后一天的价格比前一天的价格高,就可以进行交易,盈利,最后计算总利润。
18 |
19 | 代码:
20 | ```python
21 | def maxProfit(prices):
22 | if not prices:
23 | return 0
24 | max_profit = 0
25 | for i in range(0, len(prices)-1):
26 | if prices[i+1] - prices[i] > 0:
27 | max_profit += prices[i+1] - prices[i]
28 | return max_profit
29 | ```
30 |
--------------------------------------------------------------------------------
/leetcode_array/删除排序数组中的重复项.md:
--------------------------------------------------------------------------------
1 | ## 删除排序数组中的重复项
2 | 给定一个排序数组,你需要在 原地 删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。
3 | 不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成。
4 | 示例:
5 | ```python
6 | 给定 nums = [0,0,1,1,1,2,2,3,3,4],
7 | 函数应该返回新的长度 5, 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4。
8 | 你不需要考虑数组中超出新长度后面的元素。
9 | ```
10 | #### 双指针法:
11 | * 对于有序数组,利用慢指针i=0,和快指针j=1
12 | * 如果nums[i] 等于 nums[j],就增加j以跳过重复项
13 | * 如果nums[i]不等于nums[j],跳过重复项的运行已经结束,此时必须nums[j]的值复制到nums[i+1]上
14 | * 时间复杂度O(n),空间复杂度O(1)
15 |
16 | ```python
17 | def removeDuplicates(nums):
18 | i = 0
19 | for j in range(1, len(nums)):
20 | if nums[j] == nums[i]:
21 | continue
22 | i += 1
23 | nums[i] = nums[j]
24 | return i + 1
25 | ```
26 |
--------------------------------------------------------------------------------
/leetcode_array/加一.md:
--------------------------------------------------------------------------------
1 | ## 加一
2 | 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。
3 | 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。
4 | 你可以假设除了整数 0 之外,这个整数不会以零开头。
5 | 示例:
6 | ```python
7 | 输入: [4,3,2,1]
8 | 输出: [4,3,2,2]
9 | 解释: 输入数组表示数字 4321。
10 | ```
11 | #### 方法一:类型转换
12 | ```python
13 | def plusOne(digits):
14 | num = int(''.join([str(i) for i in digits])) + 1
15 | return [i for i in str(num)]
16 | ```
17 | #### 方法二:直接进行数学运算,只有+1=10的情况下才会进位
18 | ```python
19 | def plusOne(digits):
20 | # 从个位数开始+1,如果等于10,就取余向前进一位
21 | # 如果不等于10直接返回
22 | for i in range(len(digits)-1, -1, -1):
23 | digits[i] += 1
24 | digits[i] %= 10
25 | if digits[i] != 0:
26 | return digits
27 | digits.insert(0, 1)
28 | return digits
29 | ```
30 |
--------------------------------------------------------------------------------
/leetcode_array/单调数列.md:
--------------------------------------------------------------------------------
1 | 如果数组是单调递增或单调递减的,那么它是单调的。
2 | 如果对于所有 i <= j,A[i] <= A[j],那么数组 A 是单调递增的。 如果对于所有 i <= j,A[i]> = A[j],那么数组 A 是单调递减的。
3 | 当给定的数组 A 是单调数组时返回 true,否则返回 false。
4 | 示例:
5 | ```python
6 | 输入:[1,2,2,3]
7 | 输出:true
8 |
9 | 输入:[1,3,2]
10 | 输出:false
11 | ```
12 |
13 | #### 分析:
14 | * 如果数组是单调的,那一定是有序的(正序或者倒序)
15 | * 排序后进行比较就可以了
16 |
17 | 代码:
18 | ```python
19 | def isMonotonic(A):
20 | if A == sorted(A) or A == sorted(A, reverse=True):
21 | return True
22 | return False
23 | ```
24 | #### 方法二:
25 | ```python
26 | # all()函数用于判断给定的可迭代参数iterable中的所有元素是否都为TRUE
27 | def isMonotonic(A):
28 | return all([A[i] <= A[i+1] for i in range(len(A)-1)]) \
29 | or all([A[i] >= A[i+1] for i in range(len(A)-1)])
30 | ```
31 |
--------------------------------------------------------------------------------
/leetcode_array/反转字符串.md:
--------------------------------------------------------------------------------
1 | # 344.反转字符串
2 | ## 题目
3 | 编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。
4 |
5 | 不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。
6 | ```python
7 | 输入:["h","e","l","l","o"]
8 | 输出:["o","l","l","e","h"]
9 | ```
10 |
11 | ## 分析
12 | 
13 | * 左右两个指针分别从数组两端向中间运动,并交换两个指针对应的值
14 |
15 | ```python
16 | class Solution:
17 | def reverseString(self, s: List[str]) -> None:
18 | L = 0
19 | R = len(s) - 1
20 | while L < R:
21 | s[L], s[R] = s[R], s[L]
22 | L += 1
23 | R -= 1
24 | ```
25 |
--------------------------------------------------------------------------------
/leetcode_array/合并两个有序数组.md:
--------------------------------------------------------------------------------
1 | ## 合并两个有序数组
2 | 给你两个有序整数数组 nums1 和 nums2,请你将 nums2 合并到 nums1 中,使 nums1 成为一个有序数组。
3 | 说明:
4 |
5 | 初始化 nums1 和 nums2 的元素数量分别为 m 和 n 。
6 | 你可以假设 nums1 有足够的空间(空间大小大于或等于 m + n)来保存 nums2 中的元素。
7 |
8 | 示例:
9 | ```python
10 | 输入:
11 | nums1 = [1,2,3,0,0,0], m = 3
12 | nums2 = [2,5,6], n = 3
13 |
14 | 输出: [1,2,2,3,5,6]
15 | ```
16 | #### 双指针法,从后往前遍历,哪个元素大就把这个元素放在最后:
17 |
18 | ```python
19 | def merge(nums1, m, nums2, n):
20 | p1 = m - 1
21 | p2 = n - 1
22 | p = m + n -1
23 | while p1 >= 0 and p2 >= 0:
24 | if nums1[p1] >= nums2[p2]:
25 | nums1[p] = nums1[p1]
26 | p1 -= 1
27 | p -= 1
28 | else:
29 | nums1[p] = nums2[p2]
30 | p2 -= 1
31 | p -= 1
32 | if p1 < 0:
33 | nums1[:p2+1] = nums2[:p2+1]
34 | if p2 < 0:
35 | pass
36 | return nums1
37 | ```
38 |
--------------------------------------------------------------------------------
/leetcode_array/图片平滑器.md:
--------------------------------------------------------------------------------
1 | 包含整数的二维矩阵 M 表示一个图片的灰度。你需要设计一个平滑器来让每一个单元的灰度成为平均灰度 (向下舍入) ,平均灰度的计算是周围的8个单元和它本身的值求平均,如果周围的单元格不足八个,则尽可能多的利用它们。
2 | 其实就是求(i,j)周围8个点+(i,j)在内9个点的和的平均值
3 | 示例:
4 | ```python
5 | 输入:
6 | [[1,1,1],
7 | [1,0,1],
8 | [1,1,1]]
9 | 输出:
10 | [[0, 0, 0],
11 | [0, 0, 0],
12 | [0, 0, 0]]
13 | 解释:
14 | 对于点 (0,0), (0,2), (2,0), (2,2): 平均(3/4) = 平均(0.75) = 0
15 | 对于点 (0,1), (1,0), (1,2), (2,1): 平均(5/6) = 平均(0.83333333) = 0
16 | 对于点 (1,1): 平均(8/9) = 平均(0.88888889) = 0
17 | ```
18 | 代码
19 | ```python
20 | def imageSmoother(M):
21 | rows = len(M)
22 | columns = len(M[0])
23 | res = [[0] * columns for _ in range(rows)]
24 |
25 | for r in range(rows):
26 | for c in range(columns):
27 | # 计算(r,c)周边8个元素 + (r,c)在内 9个元素的和
28 | count = 0
29 | for nr in (r-1, r, r+1):
30 | for nc in (c-1, c, c+1):
31 | if 0<=nr len(nums)/2:
15 | return item
16 | ```
17 |
18 | #### 方法二:排序
19 | 将数组按照从小到大或从大到小排序后,位于len(nums)/2位置上的数一定是多数元素。
20 | * [1, 1, 1, 2, 2, 2, 2, 2], 7//2 = 3
21 | * [1, 1, 1, 2, 2, 2, 2] 6//2 = 3
22 |
23 | ```python
24 | def majorityElement(nums):
25 | nums.sort()
26 | return nums[len(nums)//2]
27 | ```
28 |
--------------------------------------------------------------------------------
/leetcode_array/子数组最大平均数I.md:
--------------------------------------------------------------------------------
1 | 给定 n 个整数,找出平均数最大且长度为 k 的连续子数组,并输出该最大平均数。
2 | 示例:
3 | ```python
4 | 输入: [1,12,-5,-6,50,3], k = 4
5 | 输出: 12.75
6 | 解释: 最大平均数 (12-5-6+50)/4 = 51/4 = 12.75
7 | ```
8 | #### 方法一:累计求和,时间复杂度O(n),空间复杂度O(n)
9 | * 遍历数组,计算原数组nums在索引i位置的累计和,存到新数组中
10 | * 遍历新数组,计算索引 i 和 i-k位置的最大差值。
11 |
12 | ```python
13 | def findMaxAverage(nums, k):
14 | sum_list = []
15 | sum_ = 0
16 | for index, item in enumerate(nums):
17 | sum_ += item
18 | sum_list.append(sum_)
19 |
20 | max_ = float('-inf')
21 | for i in range(k-1, len(sum_list)):
22 | if i == k-1:
23 | value = sum_list[i]
24 | else:
25 | value = sum_list[i] - sum_list[i-k]
26 | max_ = max(max_, value)
27 | return max_/k
28 | ```
29 | #### 方法二:滑动窗口
30 | ```python
31 | [1,2,3,4,5,6,7]
32 | # 前4位和是 1+2+3+4 = 10
33 | # 滑动遍历
34 | 2+3+4+5 = 10+5-1 = 14
35 | 3+4+5+6 = 14+6-2 = 18
36 | # 每次滑动计算子数组的和 sum = sum + nums[i] - nums[i-k]
37 | ```
38 | 代码
39 | ```python
40 | def findMaxAverage(nums, k):
41 | sum_ = sum(nums[:k])
42 | max_ = sum_
43 | for i in range(k, len(nums)):
44 | sum_ = sum_ + nums[i] - nums[i-k]
45 | max_ = max(sum_, max_)
46 | return max_/k
47 | ```
48 |
--------------------------------------------------------------------------------
/leetcode_array/存在重复元素.md:
--------------------------------------------------------------------------------
1 | 给定一个整数数组,判断是否存在重复元素。
2 | 如果任意一值在数组中出现至少两次,函数返回 true 。如果数组中每个元素都不相同,则返回 false 。
3 | 示例:
4 |
5 | ```python
6 | 输入: [1,2,3,1]
7 | 输出: true
8 | ```
9 | 代码
10 | ```python
11 | class Solution:
12 | def containsDuplicate(self, nums: List[int]) -> bool:
13 | if len(set(nums)) == len(nums):
14 | return False
15 | return True
16 | ```
17 |
--------------------------------------------------------------------------------
/leetcode_array/存在重复元素II.md:
--------------------------------------------------------------------------------
1 | 给定一个整数数组和一个整数 k,判断数组中是否存在两个不同的索引 i 和 j,使得 nums [i] = nums [j],并且 i 和 j 的差的 绝对值 至多为 k。
2 | 示例:
3 |
4 | ```python
5 | 输入: nums = [1,2,3,1], k = 3
6 | 输出: true
7 |
8 | 输入: nums = [1,0,1,1], k = 1
9 | 输出: true
10 | ```
11 |
12 | 利用哈希表:
13 |
14 | ```python
15 | def containsNearbyDuplicate(nums, k):
16 | hash_ = {}
17 | for index, item in enumerate(nums):
18 | if item not in hash_:
19 | # 元素不存在,就保存元素及索引信息
20 | hash_[item] = index
21 | else:
22 | if index - hash_[item] <= k:
23 | # 遇到重复的且索引差满足条件直接返回True
24 | return True
25 | else:
26 | # 遇到重复的,但索引差不满足条件,更新索引
27 | hash_[item] = index
28 | return False
29 | ```
30 |
--------------------------------------------------------------------------------
/leetcode_array/左旋转字符串.md:
--------------------------------------------------------------------------------
1 | # 58.2.左旋转字符串
2 | ## 题目
3 | 字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字2,该函数将返回左旋转两位得到的结果"cdefgab"。
4 | ```python
5 | 输入: s = "lrloseumgh", k = 6
6 | 输出: "umghlrlose"
7 | ```
8 |
9 | ## 分析
10 | 通过三次反转实现
11 | * 反转前n个字符: abcdefg -> bacdefg
12 | * 反转后n个字符: bacdefg -> bagfedc
13 | * 反转整个字符串: bagfedc -> cdefgab
14 |
15 | ```python
16 | def reverseLeftWords(s, n):
17 | def reverse(s):
18 | s = list(s)
19 | L = 0
20 | R = len(s) - 1
21 | while L < R:
22 | s[L], s[R] = s[R], s[L]
23 | L += 1
24 | R -= 1
25 | return ''.join(s)
26 |
27 | s_1 = reverse(s[:n])
28 | s_2 = reverse(s[n:])
29 | return reverse(s_1 + s_2)
30 | ```
31 |
32 | 如果不能使用切片,就用列表,时间复杂度O(n),空间复杂度O(n)
33 | ```python
34 | class Solution:
35 | def reverseLeftWords(self, s: str, n: int) -> str:
36 | ans = []
37 | for i in range(n, len(s)):
38 | ans.append(s[i])
39 |
40 | for i in range(n):
41 | ans.append(s[i])
42 | return ''.join(ans)
43 | ```
44 |
--------------------------------------------------------------------------------
/leetcode_array/托普利茨矩阵.md:
--------------------------------------------------------------------------------
1 | 如果矩阵上每一条由左上到右下的对角线上的元素都相同,那么这个矩阵是 托普利茨矩阵 。
2 | 给定一个 M x N 的矩阵,当且仅当它是托普利茨矩阵时返回 True。
3 | 示例:
4 | ```python
5 | 输入:
6 | matrix = [
7 | [1,2,3,4],
8 | [5,1,2,3],
9 | [9,5,1,2]
10 | ]
11 | 输出: True
12 | 解释:
13 | 在上述矩阵中, 其对角线为:
14 | "[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]"。
15 | 各条对角线上的所有元素均相同, 因此答案是True。
16 |
17 | 输入:
18 | matrix = [
19 | [1,2],
20 | [2,2]
21 | ]
22 | 输出: False
23 | 解释:
24 | 对角线"[1, 2]"上的元素不同。
25 | ```
26 | #### 分析:找规律
27 | ```python
28 | 1234
29 | 5123
30 | 9512
31 | 发现每行[0:-1] 的元素 等于 下一行[1:]
32 | ```
33 | 代码
34 | ```python
35 | def isToeplitzMatrix(matrix):
36 | if len(matrix) == 1:
37 | return True
38 | for i in range(1, len(matrix)):
39 | if matrix[i][1:] == matrix[i-1][:-1]:
40 | continue
41 | else:
42 | return False
43 | return True
44 | ```
45 |
--------------------------------------------------------------------------------
/leetcode_array/按奇偶排序数组.md:
--------------------------------------------------------------------------------
1 | 给定一个非负整数数组 A,返回一个数组,在该数组中, A 的所有偶数元素之后跟着所有奇数元素。
2 | 你可以返回满足此条件的任何数组作为答案。
3 | 示例:
4 | ```python
5 | 输入:[3,1,2,4]
6 | 输出:[2,4,3,1]
7 | 输出 [4,2,3,1],[2,4,1,3] 和 [4,2,1,3] 也会被接受。
8 | ```
9 |
10 | #### 分析:单指针
11 | 原地修改数组,遍历数组,当遇到第一个偶数时,就把这个偶数放在数组第一个位置,当遇到第二个偶数,就把这个偶数放在数组第二个位置。
12 |
13 | ```python
14 | def sortArrayByParity(A):
15 | i = 0
16 | for index, item in enumerate(A):
17 | if item%2 == 0:
18 | A[i], A[index] = item, A[i]
19 | i += 1
20 | return A
21 | ```
22 |
--------------------------------------------------------------------------------
/leetcode_array/数组中的K-diff数对.md:
--------------------------------------------------------------------------------
1 | 给定一个整数数组和一个整数 k, 你需要在数组里找到不同的 k-diff 数对。这里将 k-diff 数对定义为一个整数对 (i, j), 其中 i 和 j 都是数组中的数字,且两数之差的绝对值是 k。
2 | 示例:
3 | ```python
4 | 输入: [3, 1, 4, 1, 5], k = 2
5 | 输出: 2
6 | 数组中有两个 2-diff 数对, (1, 3) 和 (3, 5)。
7 | 尽管数组中有两个 1,但我们只应返回不同的数对的数量。
8 | ```
9 | 方法:
10 | 1. 遍历数组,两个集合,一个集合(diff)保存diff对中最小的元素,一个集合(saw)保存已经遍历过的元素。
11 | 2. 如果x-k in saw,保存x-k到diff中。
12 | 3. 如果x+k in saw,保存x到diff中。
13 | 4. 返回diff的长度.
14 | ```python
15 | def findPairs(nums, k):
16 | if k < 0:
17 | return 0
18 | diff = set()
19 | saw = set()
20 | for item in nums:
21 | if (item-k) in saw:
22 | diff.add(item-k)
23 | if (item+k) in saw:
24 | diff.add(item)
25 | saw.add(item)
26 | return len(diff)
27 | ```
28 |
--------------------------------------------------------------------------------
/leetcode_array/数组拆分I.md:
--------------------------------------------------------------------------------
1 | 给定长度为 2n 的数组, 你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), ..., (an, bn) ,使得从1 到 n 的 min(ai, bi) 总和最大。
2 | 示例:
3 | ```python
4 | 输入: [1,4,3,2]
5 | 输出: 4
6 | 解释: n 等于 2, 最大总和为 4 = min(1, 2) + min(3, 4).
7 | ```
8 | #### 方法一:排序 求和
9 | ```python
10 | 如果是min(a,b)总和最大,那排序后分组一定是相邻的两个一组。
11 | 大数跟大数分一起,小数跟小数分一起。
12 | [1,2,3,4,5,6,7,8]
13 | [(1,2),(3,4),(5,6),(7,8)]
14 | ```
15 | 代码
16 | ```python
17 | def arrayPairSum(nums):
18 | nums.sort()
19 | sum_ = 0
20 | for i in range(0, len(nums), 2):
21 | sum_ += nums[i]
22 | return sum_
23 | ```
24 |
--------------------------------------------------------------------------------
/leetcode_array/数组的度.md:
--------------------------------------------------------------------------------
1 | 给定一个非空且只包含非负数的整数数组 nums, 数组的度的定义是指数组里任一元素出现频数的最大值。
2 |
3 | 你的任务是找到与 nums 拥有相同大小的度的最短连续子数组,返回其长度。
4 | 示例:
5 | ```python
6 | 输入: [1, 2, 2, 3, 1]
7 | 输出: 2
8 | 解释:
9 | 输入数组的度是2,因为元素1和2的出现频数最大,均为2.
10 | 连续子数组里面拥有相同度的有如下所示:
11 | [1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]
12 | 最短连续子数组[2, 2]的长度为2,所以返回2.
13 |
14 | 输入: [1,2,2,3,1,4,2]
15 | 输出: 6
16 |
17 | 输入: [1,2,2,1,2,1,1,1,1,2,2,2]
18 | 输出: 9
19 | ```
20 |
21 | #### 分析:
22 | * 具有度数 d 的数组必须有一些元素 x 出现 d 次。如果某些子数组具有相同的度数,那么某些元素 x (出现 d 次)。最短的子数组是将从 x 的第一次出现到最后一次出现的数组。
23 | * 遍历数组,记录元素第一次出现的位置和最后一次出现的位置,以及每个元素出现的次数。
24 | * 找到出现次数最多的元素,计算最短子数组的长度。
25 |
26 | ```python
27 | def findShortestSubArray(nums):
28 | left, right, count = {}, {}, {}
29 | # 遍历数组,记录元素第一次出现的位置和最后一次出现的位置,以及元素出现的次数
30 | for i, item in enumerate(nums):
31 | if item not in left:
32 | left[item] = i
33 | right[item] = i
34 | count[item] = count.get(item, 0) + 1
35 |
36 | min_len = len(nums)
37 | # 找出出现次数最多的元素
38 | max_times = max(count.values())
39 | for item, times in count.items():
40 | if times == max_times:
41 | # 最小子数组的长度
42 | min_len = min(right[item] - left[item] + 1, min_len)
43 | return min_len
44 | ```
45 |
--------------------------------------------------------------------------------
/leetcode_array/斐波那契数.md:
--------------------------------------------------------------------------------
1 | 斐波那契数,通常用 F(n) 表示,形成的序列称为斐波那契数列。该数列由 0 和 1 开始,后面的每一项数字都是前面两项数字的和。也就是:
2 | ```python
3 | F(0) = 0, F(1) = 1
4 | F(N) = F(N - 1) + F(N - 2), 其中 N > 1.
5 | ```
6 | #### 递归:效率最低
7 | ```python
8 | def fib(N):
9 | if N == 0:
10 | return 0
11 | elif N == 1:
12 | return 1
13 | return fib(N-1) + fib(N-2)
14 | ```
15 | #### 自底向上计算:
16 | 自底向上通过迭代计算,把结果保存在数组中
17 | ```python
18 | def fib(N):
19 | res = [0, 1]
20 | for i in range(2, N+1):
21 | res.append(res[i-1] + res[i-2])
22 | return res[N]
23 | ```
24 |
--------------------------------------------------------------------------------
/leetcode_array/旋转数组.md:
--------------------------------------------------------------------------------
1 | ## 旋转数组
2 | 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
3 | 示例:
4 | ```python
5 | 输入: [1,2,3,4,5,6,7] 和 k = 3
6 | 输出: [5,6,7,1,2,3,4]
7 | 解释:
8 | 向右旋转 1 步: [7,1,2,3,4,5,6]
9 | 向右旋转 2 步: [6,7,1,2,3,4,5]
10 | 向右旋转 3 步: [5,6,7,1,2,3,4]
11 | ```
12 |
13 | 解析:
14 |
15 | ```python
16 | 三步反转:
17 | [1,2,3,4,5,6,7]
18 | # 第一步,反转整个数组
19 | [7,6,5,4,3,2,1]
20 | # 第二步,反转nums[:k]
21 | [5,6,7,4,3,2,1]
22 | # 第三步,反转nums[k:]
23 | [5,6,7,1,2,3,4]
24 | ```
25 |
26 | 代码:
27 |
28 | ```python
29 | def rotate(nums, k):
30 | length = len(nums)
31 | k = k%length
32 | if k == 0:
33 | return nums
34 | nums[:] = nums[::-1]
35 | nums[:k] = nums[:k][::-1]
36 | nums[k:] = nums[k:][::-1]
37 | return nums
38 | ```
39 |
--------------------------------------------------------------------------------
/leetcode_array/替换空格.md:
--------------------------------------------------------------------------------
1 | # 05.替换空格
2 | ## 题目
3 | 请实现一个函数,把字符串 s 中的每个空格替换成"%20"。
4 | ```python
5 | 输入:s = "We are happy."
6 | 输出:"We%20are%20happy."
7 | ```
8 |
9 | ## 分析
10 | * 初始化一个长度数组,长度为字符串长度的3倍
11 | * 指针指向初始化数组的头部
12 | * 遍历字符串,如果字符是空,就填充"%", "2", "0",指针前进三步,如果不是空,填充字符,指针前进一步
13 |
14 | ```python
15 | def replaceSpace(s):
16 | ans = ['' for _ in range(len(s)*3)]
17 | size = 0
18 | for char in s:
19 | if char == ' ':
20 | ans[size], ans[size+1], ans[size+2] = "%", "2", "0"
21 | size += 3
22 | else:
23 | ans[size] = char
24 | size += 1
25 | return ''.join(ans[:size])
26 | ```
27 |
28 | 
29 | ```python
30 | def replaceSpace(s):
31 | ans = []
32 | for char in s:
33 | ans.append(char) if char != ' ' else ans.append("%20")
34 | return ''.join(ans)
35 | ```
36 |
--------------------------------------------------------------------------------
/leetcode_array/最大子序和.md:
--------------------------------------------------------------------------------
1 | ## 最大子序和
2 | 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
3 | 示例:
4 |
5 | ```python
6 | 输入: [-2,1,-3,4,-1,2,1,-5,4],
7 | 输出: 6
8 | 解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。
9 | ```
10 | 如果当前元素的前一个元素大于0,就将当前元素加上前一个元素。例如:
11 | ```python
12 | [-2,1,-3,4,-1,2,1,-5,4]
13 | [-2,1,-2,4, 3,5,6, 1,5]
14 | ```
15 | 代码:
16 | ```python
17 | def maxSubArray(nums):
18 | for i in range(1, len(nums)):
19 | if nums[i-1] > 0:
20 | nums[i] += nums[i-1]
21 | return max(nums)
22 | ```
23 |
--------------------------------------------------------------------------------
/leetcode_array/最大连续1的个数.md:
--------------------------------------------------------------------------------
1 | 给定一个二进制数组, 计算其中最大连续1的个数。
2 | 示例:
3 | ```python
4 | 输入: [1,1,0,1,1,1]
5 | 输出: 3
6 | 解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 3.
7 | ```
8 | 代码
9 | ```python
10 | def findMaxConsecutiveOnes(nums):
11 | max_ones = 0
12 | tmp_max_ones = 0
13 | for item in nums:
14 | if item == 1:
15 | tmp_max_ones += 1
16 | else:
17 | max_ones = max(tmp_max_ones, max_ones)
18 | tmp_max_ones = 0
19 | max_ones = max(tmp_max_ones, max_ones)
20 | return max_ones
21 | ```
22 |
--------------------------------------------------------------------------------
/leetcode_array/最短无序连续子数组.md:
--------------------------------------------------------------------------------
1 | 给定一个整数数组,你需要寻找一个连续的子数组,如果对这个子数组进行升序排序,那么整个数组都会变为升序排序。
2 | 你找到的子数组应是最短的,请输出它的长度。
3 | 示例:
4 | ```python
5 | 输入: [2, 6, 4, 8, 10, 9, 15]
6 | 输出: 5
7 | 解释: 你只需要对 [6, 4, 8, 10, 9] 进行升序排序,那么整个表都会变为升序排序。
8 | ```
9 | #### 解析:
10 | * 对原数组进行排序
11 | * 排序后的数组与原数组进行比较
12 |
13 | ```python
14 | [2, 6, 4, 8, 10, 9, 15]
15 | [2, 4, 6, 8, 9, 10, 15]
16 | 对比即可发现最短无序数组
17 | ```
18 | 代码
19 | ```python
20 | class Solution:
21 | def findUnsortedSubarray(self, nums: List[int]) -> int:
22 | nums_ = nums.copy()
23 | nums.sort()
24 | start, end = 0, 0
25 | flag = False
26 | for index, item in enumerate(nums_):
27 | if item != nums[index]:
28 | if not flag:
29 | start = index
30 | flag = True
31 | else:
32 | end = index + 1
33 | return end - start
34 | ```
35 |
--------------------------------------------------------------------------------
/leetcode_array/最长连续递增序列.md:
--------------------------------------------------------------------------------
1 | 给定一个未经排序的整数数组,找到最长且连续的的递增序列,并返回该序列的长度。
2 | 示例:
3 | ```python
4 | 输入: [1,3,5,4,7]
5 | 输出: 3
6 | 解释: 最长连续递增序列是 [1,3,5], 长度为3。
7 | 尽管 [1,3,5,7] 也是升序的子序列, 但它不是连续的,因为5和7在原数组里被4隔开。
8 | ```
9 | #### 方法一:累计计算
10 | ```python
11 | def findLengthOfLCIS(nums):
12 | if not nums:
13 | return 0
14 | count = 1
15 | max_count = 1
16 | for i in range(len(nums)-1):
17 | if nums[i] < nums[i+1]:
18 | count += 1
19 | max_count = max(max_count, count)
20 | else:
21 | count = 1
22 | return max_count
23 | ```
24 |
--------------------------------------------------------------------------------
/leetcode_array/杨辉三角II.md:
--------------------------------------------------------------------------------
1 | ## 杨辉三角 II
2 | 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。
3 | ```python
4 | [
5 | [1], 0
6 | [1,1], 1
7 | [1,2,1], 2
8 | [1,3,3,1], 3
9 | [1,4,6,4,1] 4
10 | ]
11 | ```
12 | 示例:
13 | ```python
14 | 输入: 3
15 | 输出: [1,3,3,1]
16 | ```
17 |
18 | 代码:
19 | ```python
20 | class Solution:
21 | def getRow(self, rowIndex: int) -> List[int]:
22 | if rowIndex == 0:
23 | return [1]
24 | elif rowIndex == 1:
25 | return [1, 1]
26 | else:
27 | list_ = self.getRow(rowIndex-1)
28 | res = []
29 | for i in range(1, len(list_)):
30 | res.append(list_[i]+list_[i-1])
31 | res = [1] + res + [1]
32 | return res
33 | ```
34 |
--------------------------------------------------------------------------------
/leetcode_array/移动零.md:
--------------------------------------------------------------------------------
1 | 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。
2 | 示例:
3 | 输入: [0,1,0,3,12]
4 | 输出: [1,3,12,0,0]
5 |
6 | 暴力法:
7 | 两个指针,从第一个元素开始遍历数组,如果是0,就与下一个不为0的元素交换位置
8 | ```python
9 | def moveZeroes(nums):
10 | for i in range(0, len(nums)-1):
11 | for j in range(i+1, len(nums)):
12 | if nums[i] == 0 and nums[j] == 0:
13 | continue
14 | if nums[i] == 0 and nums[j] != 0:
15 | nums[i], nums[j] = nums[j], nums[i]
16 | if nums[i] != 0:
17 | break
18 | return nums
19 | ```
20 | 双指针:
21 | ```python
22 | def moveZeroes(nums):
23 | i = 0
24 | for j in range(len(nums)):
25 | if nums[j]:
26 | # 不为0,就交换位置
27 | nums[i], nums[j] = nums[j], nums[i]
28 | i += 1
29 | ```
30 |
--------------------------------------------------------------------------------
/leetcode_array/移除元素.md:
--------------------------------------------------------------------------------
1 | ## 27.移除元素
2 | 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。
3 |
4 | 不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。
5 |
6 | 元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。
7 |
8 | 示例:
9 | ```python
10 | 给定 nums = [0,1,2,2,3,0,4,2], val = 2,
11 | 函数应该返回新的长度 5, 并且 nums 中的前五个元素为 0, 1, 3, 0, 4。
12 | 注意这五个元素可为任意顺序。
13 | ```
14 |
15 | #### 双指针法:
16 | **i是慢指针,j是快指针,当nums[j]与给定的值相等时,递增j以跳过该元素。只要nums[j]!=给定值,就复制nums[j]到nums[i] 并同时递增两个索引。重复这一过程,直到j到达数组的末尾**
17 |
18 | * 慢指针i=0,快指针j从0开始遍历数组。
19 | * 当nums[j]等于目标值的时候,跳过。
20 | * 当nums[j]不等于目标值的时候,nums[j]复制给nums[i],i递增。
21 | * 时间复杂度O(n),空间复杂度O(1)
22 |
23 | 
24 | 
25 |
26 | ```python
27 | def removeElement(nums, val):
28 | i = 0
29 | for j in range(0, len(nums)):
30 | if nums[j] == val:
31 | continue
32 | nums[i] = nums[j]
33 | i += 1
34 | return i
35 | ```
36 |
--------------------------------------------------------------------------------
/leetcode_array/第三大的数.md:
--------------------------------------------------------------------------------
1 | 给定一个非空数组,返回此数组中第三大的数。如果不存在,则返回数组中最大的数。要求算法时间复杂度必须是O(n)。
2 | 示例:
3 | ```python
4 | 输入: [2, 2, 3, 1]
5 | 输出: 1
6 | 解释: 注意,要求返回第三大的数,是指第三大且唯一出现的数。
7 | 存在两个值为2的数,它们都排第二。
8 |
9 | 输入: [1, 2]
10 | 输出: 2
11 | 解释: 第三大的数不存在, 所以返回最大的数 2 .
12 | ```
13 | #### 方法一:去重,排序
14 | ```python
15 | def thirdMax(nums):
16 | nums = list(set(nums))
17 | nums.sort()
18 | if len(nums) >= 3:
19 | return nums[-3]
20 | else:
21 | return nums[-1]
22 | ```
23 | #### 方法二:定义三个变量存储最大的三个数
24 | ```python
25 | def thirdMax(nums):
26 | max_1 = float('-inf')
27 | max_2 = float('-inf')
28 | max_3 = float('-inf')
29 | for item in nums:
30 | if item > max_1:
31 | # 第一大的数更新后,原来的第一大变为第二大,第二大变为第三大
32 | max_3 = max_2
33 | max_2 = max_1
34 | max_1 = item
35 | elif max_2 < item < max_1:
36 | # 第二大的数更新后,原来的第二大变为第三大
37 | max_3 = max_2
38 | max_2 = item
39 | elif max_3 < item < max_2:
40 | max_3 = item
41 | if max_3 == float('-inf'):
42 | return max_1
43 | return max_3
44 | ```
45 |
--------------------------------------------------------------------------------
/leetcode_array/缺失数字.md:
--------------------------------------------------------------------------------
1 | 给定一个包含 0, 1, 2, ..., n 中 n 个数的序列,找出 0 .. n 中没有出现在序列中的那个数。
2 | 示例:
3 | ```python
4 | 输入: [3,0,1]
5 | 输出: 2
6 | 输入:[0]
7 | 输出: 1
8 | ```
9 |
10 | 代码
11 | ```python
12 | def missingNumber(nums):
13 | nums.sort()
14 | for index, item in enumerate(nums):
15 | if index != item:
16 | return index
17 | return len(nums)
18 | ```
19 |
20 | #### 数学求和
21 | 长度为n的数组,正常应该是 sum1 = 0+1+2+3……+n = (n+1)*n/2
22 | 如果少了一个数,sum1 - sum(nums),则为少的那个数
23 | ```python
24 | def missingNumber(nums):
25 | l = len(nums)
26 | # 求和 [0, 1, 3] = 0+1+2+3 = (l+1)*l/2
27 | sum1 = (l + 1)*l/2
28 | # [0,1,3] = 0+1+3
29 | sum2 = sum(nums)
30 | return int(sum1 - sum2)
31 | ```
32 |
--------------------------------------------------------------------------------
/leetcode_array/翻转图像.md:
--------------------------------------------------------------------------------
1 | 给定一个二进制矩阵 A,我们想先水平翻转图像,然后反转图像并返回结果。
2 | 水平翻转图片就是将图片的每一行都进行翻转,即逆序。例如,水平翻转 [1, 1, 0] 的结果是 [0, 1, 1]。
3 | 反转图片的意思是图片中的 0 全部被 1 替换, 1 全部被 0 替换。例如,反转 [0, 1, 1] 的结果是 [1, 0, 0]。
4 | 示例:
5 | ```python
6 | 输入: [[1,1,0],[1,0,1],[0,0,0]]
7 | 输出: [[1,0,0],[0,1,0],[1,1,1]]
8 | 解释: 首先翻转每一行: [[0,1,1],[1,0,1],[0,0,0]];
9 | 然后反转图片: [[1,0,0],[0,1,0],[1,1,1]]
10 | ```
11 | #### 代码:简单粗暴,时间复杂度 O(M∗N),空间复杂度O(M∗N)
12 | ```python
13 | def flipAndInvertImage(A):
14 | res = []
15 | for row in A:
16 | # 水平翻转
17 | row.reverse()
18 | # 0 1替换
19 | new_row = [0 if item else 1 for item in row]
20 | res.append(new_row)
21 | return res
22 | ```
23 |
--------------------------------------------------------------------------------
/leetcode_array/至少是其他数字两倍的最大数.md:
--------------------------------------------------------------------------------
1 | 在一个给定的数组nums中,总是存在一个最大元素 。
2 | 查找数组中的最大元素是否至少是数组中每个其他数字的两倍。
3 | 如果是,则返回最大元素的索引,否则返回-1。
4 | 示例:
5 | ```python
6 | 输入: nums = [3, 6, 1, 0]
7 | 输出: 1
8 | 解释: 6是最大的整数, 对于数组中的其他整数,
9 | 6大于数组中其他元素的两倍。6的索引是1, 所以我们返回1.
10 |
11 | 输入: nums = [1, 2, 3, 4]
12 | 输出: -1
13 | 解释: 4没有超过3的两倍大, 所以我们返回 -1.
14 | ```
15 |
16 | #### 分析:
17 | * 找到最大的元素
18 | * 分别于数组中的每个元素进行比较
19 | * 如果所有元素的2倍值都小于最大的元素,返回最大元素的索引
20 |
21 | ```python
22 | def dominantIndex(nums):
23 | res = -1
24 | max_ = max(nums)
25 | for index, num in enumerate(nums):
26 | if max_ == num:
27 | res = index
28 | else:
29 | if num * 2 > max_:
30 | return -1
31 | return res
32 | ```
33 |
--------------------------------------------------------------------------------
/leetcode_array/螺旋矩阵2.md:
--------------------------------------------------------------------------------
1 | # 59.螺旋矩阵II
2 | 给你一个正整数n,生成一个包含1到n2所有元素,且元素按顺时针顺序螺旋排列的nxn正方形矩阵matrix。
3 | 
4 |
5 | ## 模拟顺时针顺序填充矩阵
6 | **模拟四个方向**
7 | * 从左向右:行索引不变,列索引增大
8 | * 从上向下:行索引增大,列索引不变
9 | * 从右向左:行索引不变,列索引减小
10 | * 从下向上:行索引减小,列索引不变
11 | * 初始化元素全部为0,当索引越界,或者碰到不为0的值,就应该改变方向
12 |
13 | ```python
14 | def generateMatrix(n):
15 | # 定义四个移动方向
16 | # (0, 1): 从左向右, row+0, col+1
17 | # (1, 0): 从上向下 row+1, col+0
18 | # (0, -1): 从右向左 row+0, col-1
19 | # (-1, 0): 从下向上 row-1, col+0
20 | dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)]
21 | # 初始化
22 | matrix = [[0] * n for _ in range(n)]
23 | row, col, dirs_index = 0, 0, 0
24 | for i in range(1, n*n+1):
25 | matrix[row][col] = i
26 | # 计算下一个填充位置
27 | dx, dy = dirs[dirs_index]
28 | r = row + dx
29 | c = col + dy
30 | if r >= n or r < 0 or c >= n or c < 0 or matrix[r][c] > 0:
31 | # 改变方向
32 | dirs_index = (dirs_index + 1) % 4
33 | dx, dy = dirs[dirs_index]
34 | row = row + dx
35 | col = col + dy
36 |
37 | return matrix
38 | ```
39 |
--------------------------------------------------------------------------------
/leetcode_array/转置矩阵.md:
--------------------------------------------------------------------------------
1 | 给定一个矩阵 A, 返回 A 的转置矩阵。
2 | 矩阵的转置是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引。
3 | 示例:
4 | ```python
5 | 输入:[[1,2,3],[4,5,6]]
6 | 输出:[[1,4],[2,5],[3,6]]
7 | ```
8 | #### 分析:
9 | M\*N矩阵转置后 为N\*M
10 |
11 | 代码:
12 | ```python
13 | def transpose(A):
14 | if not A:
15 | return []
16 | rows = len(A)
17 | columns = len(A[0])
18 |
19 | # 构建一个空的转置矩阵
20 | res = [[0 for __ in range(rows)] for _ in range(columns)]
21 |
22 | for r in range(rows):
23 | for c in range(columns):
24 | res[c][r] = A[r][c]
25 | return res
26 | ```
27 |
--------------------------------------------------------------------------------
/leetcode_array/长度最小的子数组.md:
--------------------------------------------------------------------------------
1 | # 209.长度最小的子数组
2 | 给定一个含有 n 个正整数的数组和一个正整数target。
3 |
4 | 找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl+1, ..., numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回0。
5 |
6 | ```python
7 | 输入:target = 7, nums = [2,3,1,2,4,3]
8 | 输出:2
9 | 解释:子数组 [4,3] 是该条件下的长度最小的子数组。
10 | ```
11 |
12 | 
13 |
14 | * 定义窗口的起始指针和结束指针
15 | * 当窗口内的值总和小于目标值时,不断移动窗口的结束指针,扩大窗口
16 | * 当窗口内的值总和满足目标情况,不断移动起始指针,缩小窗口
17 | * 用一个变量记录最小窗口长度
18 |
19 | ```python
20 | def minSubArrayLen(target, nums):
21 | start = 0
22 | # 初始化返回值
23 | ans = len(nums) + 1
24 | sum = 0
25 |
26 | for end in range(0, len(nums)):
27 | sum += nums[end]
28 |
29 | while sum >= target:
30 | # 窗口内的值总和满足条件
31 | win_length = end - start + 1 # 窗口长度
32 | ans = min(ans, win_length)
33 | sum -= nums[start]
34 | start += 1
35 |
36 | if ans > len(nums):
37 | return 0
38 | return ans
39 | ```
40 |
--------------------------------------------------------------------------------
/leetcode_array/非递减数列.md:
--------------------------------------------------------------------------------
1 | 给你一个长度为 n 的整数数组,请你判断在 最多 改变 1 个元素的情况下,该数组能否变成一个非递减数列。
2 | 我们是这样定义一个非递减数列的: 对于数组中所有的 i (0 <= i <= n-2),总满足 nums[i] <= nums[i + 1]。
3 | 上述非递减数列的定义其实就是递增数列。
4 | 示例:
5 | ```python
6 | 输入: nums = [4,2,3]
7 | 输出: true
8 | 解释: 你可以通过把第一个4变成1来使得它成为一个非递减数列。
9 |
10 | [1,2,3,4,3,5]
11 | # 遍历数组,如果nums[i] < nums[i-1]有两种情况
12 | # 可能是nums[i]太小
13 | # 也可能是nums[i-1]太大
14 | # 上述数组,可以把4变为3,也可以把3变为4.
15 | # 无论是哪种情况,如果满足题目条件的话,只要移除i 或者 i-1后,数组必然是递增的。
16 | ```
17 |
18 | 代码
19 | ```python
20 | class Solution:
21 | def is_non_reduce(self, nums_):
22 | for i in range(1, len(nums_)):
23 | if nums_[i] < nums_[i - 1]:
24 | return False
25 | return True
26 |
27 | def checkPossibility(self, nums: List[int]) -> bool:
28 | index = None
29 | # 找到元素突然变小位置的索引
30 | for i in range(1, len(nums)):
31 | if nums[i] >= nums[i-1]:
32 | continue
33 | index = i
34 | break
35 |
36 | if index is None:
37 | # 原数组本来就是递增的,不需要改变任何元素
38 | return True
39 |
40 | # 分别删除 i 或者 i-1判断数组是否递增
41 | for i in (index, index-1):
42 | if i < 0:
43 | continue
44 | nums_ = nums.copy()
45 | nums_.pop(i)
46 | if self.is_non_reduce(nums_):
47 | return True
48 | return False
49 | ```
50 |
--------------------------------------------------------------------------------
/leetcode_hash/main.md:
--------------------------------------------------------------------------------
1 | # LeetCode哈希表
2 | ## 定义
3 | **哈希表,也叫散列表,是可以通过关键字key访问映射表来得到value的地址,从而可以直接通过key获取其对应的value的值的数据结构,这个映射表也叫哈希函数,存放value的数组叫做哈希表。**
4 |
5 | 给定表M,存在函数f(key),对任意给定的关键字值key,代入函数后若能得到包含该关键字的记录在表中的地址,则称表M为哈希(Hash)表,函数f(key)为哈希(Hash) 函数。
6 |
7 | #### 哈希冲突:不同的key通过哈希计算,得到了相同的地址,就会产生哈希冲突。
8 | 解决哈希冲突的方法:
9 | 1. 链地址法:对Key通过哈希之后落在同一个地址上的值,做一个链表来进行存储同一个key对应的不同的值。
10 | 2. 开放地址法:如果出现一个key2进行hash(key)后映射的位置与key1进行hash(key)后映射的位置一致(即发生了哈希冲突),那么从该位置往下寻找到第一个空位时将key2的数据放入。而从该位置往下寻找空闲位置的过程又称为探测。
11 |
12 | ## 题目
13 | * [有效的字母异位词](有效的字母异位词.md)
14 | * [两个数组的交集](两个数组的交集.md)
15 | * [快乐数](快乐数.md)
16 | * [两数之和](两数之和.md)
17 | * [四数相加II](四数相加II.md)
18 | * [赎金信](赎金信.md)
19 |
--------------------------------------------------------------------------------
/leetcode_hash/两个数组的交集.md:
--------------------------------------------------------------------------------
1 | # 349.两个数组的交集
2 | ## 题目
3 | 给定两个数组,编写一个函数来计算它们的交集。
4 | ```python
5 | 输入:nums1 = [1,2,2,1], nums2 = [2,2]
6 | 输出:[2]
7 |
8 | 输入:nums1 = [4,9,5], nums2 = [9,4,9,8,4]
9 | 输出:[9,4]
10 | ```
11 |
12 | ## 分析
13 | * 将列表转换为集合,集合的特性是去重,查找时间复杂度O(1)
14 | * 遍历其中一个集合,判断元素在另一个集合中是否出现
15 | * 时间复杂度O(m+n):其中m和n分别是两个数组的长度。使用两个集合分别存储两个数组中的元素需要O(m+n)的时间,遍历较小的集合并判断元素是否在另一个集合中需要O(min(m,n))的时间,因此总时间复杂度是O(m+n)。
16 | * 空间复杂度:O(m+n)
17 |
18 | ```python
19 | def intersection(nums1, nums2):
20 | set1 = set(nums1)
21 | set2 = set(nums2)
22 | if len(set1) < len(set2):
23 | # 遍历短的提高效率
24 | return [item for item in set1 if item in set2]
25 | return [item for item in set2 if item in set1]
26 | ```
27 |
--------------------------------------------------------------------------------
/leetcode_hash/两数之和.md:
--------------------------------------------------------------------------------
1 | # 1.两数之和
2 | ## 题目
3 | 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
4 | 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。
5 | 示例:
6 | ```python
7 | 给定 nums = [2, 7, 11, 15], target = 9
8 | 因为 nums[0] + nums[1] = 2 + 7 = 9
9 | 所以返回 [0, 1]
10 |
11 | nums = [3,3],target=6
12 | [0,1]
13 | ```
14 |
15 | ## 分析
16 | 用字典存储每个元素及其对应的索引。时间复杂度O(n),空间复杂度O(n)
17 |
18 | * 从前向后依次遍历数组中的元素。
19 | * 计算差值,如果差值不存在字典中,则保存当前遍历的元素到字典中。
20 | * 如果差值存在字典中,返回差值的索引与当前元素的索引。
21 |
22 | ```python
23 | def twoSum(nums, target):
24 | hash_table = {}
25 | for index, item in enumerate(nums):
26 | other = target - item
27 | if other in hash_table:
28 | return [index, hash_table[other]]
29 | hash_table[item] = index
30 | ```
31 |
--------------------------------------------------------------------------------
/leetcode_hash/四数相加II.md:
--------------------------------------------------------------------------------
1 | # 454.四数相加II
2 | ## 题目
3 | 给定四个包含整数的数组列表 A , B , C , D ,计算有多少个元组 (i, j, k, l) ,使得 A[i] + B[j] + C[k] + D[l] = 0。
4 | ```python
5 | 输入:
6 | A = [ 1, 2]
7 | B = [-2,-1]
8 | C = [-1, 2]
9 | D = [ 0, 2]
10 | 输出:
11 | 2
12 | 解释:
13 | 两个元组如下:
14 | 1. (0, 0, 0, 1) -> A[0] + B[0] + C[0] + D[1] = 1 + (-2) + (-1) + 2 = 0
15 | 2. (1, 1, 0, 0) -> A[1] + B[1] + C[0] + D[0] = 2 + (-1) + (-1) + 0 = 0
16 | ```
17 |
18 | ## 分析
19 | * 与[两数之和](两数之和.md)有点相似,将四个数组分成两组,AB一组,CD一组
20 | * 对于A和B,使用二重循环对它们进行遍历,得到所有A[i]+B[j]的值并存入哈希映射中。每个键表示一种A[i]+B[j],对应的值为 A[i]+B[j]出现的次数。
21 | * 对于C和D,同样使用二重循环对它们进行遍历。当遍历到C[k]+D[l] 时,如果-(C[k]+D[l])出现在哈希映射中,那么将 -(C[k]+D[l])对应的值累加进答案中。
22 | * 时间复杂度O(n^2), 空间复杂度O(n^2)
23 |
24 | ```python
25 | def fourSumCount(A, B, C, D):
26 | # 记录AB两个数组元素两两相加之和及其次数
27 | hash_1 = dict()
28 | for index_1, item_1 in enumerate(A):
29 | for index_2, item_2 in enumerate(B):
30 | sum_ = item_1 + item_2
31 | hash_1[sum_] = hash_1.get(sum_, 0) + 1
32 |
33 | ans = 0
34 | for index_1, item_1 in enumerate(C):
35 | for index_2, item_2 in enumerate(D):
36 | sum_ = item_1 + item_2
37 | if 0-sum_ in hash_1:
38 | ans += hash_1[0-sum_]
39 |
40 | return ans
41 | ```
42 |
--------------------------------------------------------------------------------
/leetcode_hash/快乐数.md:
--------------------------------------------------------------------------------
1 | # 202.快乐数
2 | ## 题目
3 | 编写一个算法来判断一个数 n 是不是快乐数。
4 | * 对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和。
5 | * 然后重复这个过程直到这个数变为 1,也可能是 无限循环 但始终变不到 1。
6 | * 如果 可以变为 1,那么这个数就是快乐数。
7 | ```python
8 | 输入:19
9 | 输出:true
10 | 解释:
11 | 1 + 81 = 82
12 | 64 + 4 = 68
13 | 36 + 64 = 100
14 | 1 + 0 + 0 = 1
15 | ```
16 |
17 | ## 分析
18 | * 可能最终会得到1
19 | * 可能最终会无限循环
20 | * 会不会无限增大
21 |
22 | #### 为什么不会无限变大
23 | * 如果是一位数,最大为9,平方和最大是81
24 | * 如果是两位数,最大为99,平方和最大为162
25 | * 如果是三位数,最大为999,平方和最大为243
26 | * 如果是四位数,最大为9999,平方和最大为324
27 |
28 | **所以对于三位数的整数,它的下一个数字(每个位置数字的平方和)不会大于243,对于四位和四位以上的整数,每次计算都会减小,最终变为三位数的整数,所以结果不会无限增大,算法可能会在243以下的所有数字上循环,然后回到它已经到过的一个循环或者回到1。**
29 |
30 | **判断元素是否重复出现就要考虑使用哈希表。**
31 | * 逐个计算下一个数字,并将结果保存在哈希表中
32 | * 如果结果出现1,返回True
33 | * 如果出现重复的结果,说明出现循环,返回False
34 | 
35 | 
36 |
37 | ```python
38 | class Solution:
39 | def isHappy(self, n: int) -> bool:
40 | def get_next(n):
41 | sum = 0
42 | while n > 0:
43 | sum += (n % 10) ** 2
44 | n = n // 10
45 | return sum
46 |
47 | hash_table = dict()
48 | while n not in hash_table:
49 | if n == 1:
50 | return True
51 | hash_table[n] = None
52 | n = get_next(n)
53 |
54 | return False
55 | ```
56 |
--------------------------------------------------------------------------------
/leetcode_hash/有效的字母异位词.md:
--------------------------------------------------------------------------------
1 | # 242.有效的字母异位词
2 | ## 题目
3 | 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。
4 | ```python
5 | 输入: s = "anagram", t = "nagaram"
6 | 输出: true
7 |
8 | 输入: s = "rat", t = "car"
9 | 输出: false
10 | ```
11 |
12 | ## 解析
13 | * 如果两个字符串长度不相等直接返回False
14 | * 利用两个字典统计每个字符串中字符出现的次数
15 | * 如果两个字典相等,返回True
16 |
17 | ```python
18 | def isAnagram(s, t):
19 | if len(s) != len(t):
20 | return False
21 |
22 | if s == t:
23 | return True
24 |
25 | hash_s = {}
26 | hash_t = {}
27 | for i in range(len(s)):
28 | hash_s[s[i]] = hash_s.get(s[i], 0) + 1
29 | hash_t[t[i]] = hash_t.get(t[i], 0) + 1
30 |
31 | return hash_t == hash_s
32 | ```
33 |
--------------------------------------------------------------------------------
/leetcode_hash/赎金信.md:
--------------------------------------------------------------------------------
1 | # 383.赎金信
2 | ## 题目
3 | 给定一个赎金信 (ransom) 字符串和一个杂志(magazine)字符串,判断第一个字符串 ransom 能不能由第二个字符串 magazines 里面的字符构成。如果可以构成,返回 true ;否则返回 false。
4 |
5 | (题目说明:为了不暴露赎金信字迹,要从杂志上搜索各个需要的字母,组成单词来表达意思。杂志字符串中的每个字符只能在赎金信字符串中使用一次。)
6 |
7 | ```python
8 | 输入:ransomNote = "a", magazine = "b"
9 | 输出:false
10 |
11 | 输入:ransomNote = "aa", magazine = "aab"
12 | 输出:true
13 | ```
14 |
15 | ## 分析
16 | * 根据题目分析,ransom中字符出现的个数必须小于等于magazine中字符出现的次数
17 | * 分别统计ransom,magazine中字符出现的次数
18 | * 比较ransom,magazine每个字符出现的次数
19 |
20 | ```python
21 | def canConstruct(ransomNote, magazine):
22 | hash_1 = dict()
23 | hash_2 = dict()
24 | for char in ransomNote:
25 | hash_1[char] = hash_1.get(char, 0) + 1
26 | for char in magazine:
27 | hash_2[char] = hash_2.get(char, 0) + 1
28 |
29 | for char, times in hash_1.items():
30 | if hash_2.get(char, 0) < times:
31 | return False
32 | return True
33 | ```
34 |
--------------------------------------------------------------------------------
/leetcode_linked_list/main.md:
--------------------------------------------------------------------------------
1 | # LeetCode链表
2 | ## 1.定义
3 | **链表是一种物理存储单元上非连续,非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现。**
4 |
5 | **链表中每个元素称为节点,节点包括两部分,一是存储数据元素的数据域,一是存储下一个节点地址的指针域。**
6 |
7 | **由于不必按照顺序存储,链表插入和删除元素的时间复杂度O(1),查找元素的时间复杂度O(n)**
8 |
9 | ## 2.数组与链表比较、
10 | * 从逻辑结构方面,两者都属于线性表,数组是顺序存储结构的线性表,链表是链式存储结构的线性表。
11 | * 从物理内存方面,数组占用的是一段连续的内存区,链表在内存中是非连续的,分散的,是通过指针实现逻辑上的线性表。
12 | * 对于访问,由于数组在内存上是连续的,所以支持“随机访问”,时间复杂度O(1),而链表是非连续的内存空间,只能通过“顺序访问”,时间复杂度O(n)
13 | * 对于插入/删除元素,数组的时间复杂度O(n),链表的时间复杂度O(1)
14 |
15 | ## 3.题目
16 | * [移除链表元素(虚拟头结点)](移除链表元素.md)
17 | * [设计链表(虚拟头结点)](设计链表.md)
18 | * [反转链表(双指针)](反转链表.md)
19 | * [删除链表的倒数第N个结点(双指针)](删除链表的倒数第N个结点.md)
20 | * [环形链表II(快慢指针)](环形链表II.md)
21 |
22 |
34 |
--------------------------------------------------------------------------------
/leetcode_linked_list/二进制链表转整数.md:
--------------------------------------------------------------------------------
1 | ## 二进制链表转整数
2 | 给你一个单链表的引用结点 head。链表中每个结点的值不是 0 就是 1。已知此链表是一个整数数字的二进制表示形式。
3 |
4 | 请你返回该链表所表示数字的 十进制值 。
5 |
6 | #### 示例
7 | ```python
8 | 输入:head = [1,0,1]
9 | 输出:5
10 | 解释:二进制数 (101) 转化为十进制数 (5)
11 | ```
12 |
13 | #### 代码
14 | **从低位到高位计算**
15 |
16 | ```python
17 | abcd(2) = d*(2**0) + c*(2**1) + b*(2**2) + a*(2**3) (10)
18 | ```
19 |
20 | * 把链表的值保存在列表中
21 | * 反向遍历列表计算出十进制
22 |
23 | ```python
24 | class Solution:
25 | def getDecimalValue(self, head: ListNode) -> int:
26 | cur = head
27 | val_list = []
28 | while cur:
29 | var = cur.val
30 | val_list.append(var)
31 | cur = cur.next
32 | res = 0
33 | for index, item in enumerate(val_list[::-1]):
34 | res += item * (2**index)
35 | return res
36 | ```
37 |
38 | **从低位到高位计算**
39 | ```python
40 | 根据十进制转二进制
41 | 8(10) --> 1000(2)
42 | 8 / 2 = 4 余 0
43 | 4 / 2 = 2 余 0
44 | 2 / 2 = 1 余 0
45 | 1 / 2 = 0 余 1
46 |
47 | abcd(2)
48 |
49 | res = (0*2) + a
50 | res = (res*2) + b
51 | res = (res*2) + c
52 | res = (res*2) + d
53 | ```
54 |
55 | ```python
56 | def getDecimalValue(head):
57 | cur = head
58 | res = 0
59 | while cur:
60 | res = res * 2 + cur.val
61 | cur = cur.next
62 |
63 | return res
64 | ```
65 |
--------------------------------------------------------------------------------
/leetcode_linked_list/删除排序链表中的重复元素.md:
--------------------------------------------------------------------------------
1 | ## 删除排序链表中的重复元素
2 | 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
3 | 示例:
4 | ```python
5 | 输入: 1->1->2->3->3
6 | 输出: 1->2->3
7 |
8 | 输入: 1->1->2
9 | 输出: 1->2
10 | ```
11 |
12 | #### 代码
13 | * 指针指向头部节点
14 | * 指针当前节点值与下一个节点值相同,则跳过下一个节点,到下下个节点
15 | * 指针当前节点与下一个节点值不同,指针指向下一个节点
16 | ```python
17 | def deleteDuplicates(head):
18 | cur = head
19 | while cur and cur.next:
20 | if cur.val == cur.next.val:
21 | cur.next = cur.next.next
22 | else:
23 | cur = cur.next
24 | return head
25 | ```
26 |
--------------------------------------------------------------------------------
/leetcode_linked_list/删除链表中的节点.md:
--------------------------------------------------------------------------------
1 | ## 删除链表中的节点
2 | 请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点。**传入函数的唯一参数为 要被删除的节点** 。
3 |
4 | * 链表至少包含两个节点。
5 | * 链表中所有节点的值都是唯一的。
6 | * 给定的节点为非末尾节点并且一定是链表中的一个有效节点。
7 | * 不要从你的函数中返回任何结果。
8 |
9 | #### 示例
10 | ```python
11 | 输入:head = [4,5,1,9], node = 5
12 | 输出:[4,1,9]
13 | 解释:给定你链表中值为 5 的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9.
14 | ```
15 |
16 | #### 代码
17 | 与之前做过的一个题目很像,[移除链表元素(两个指针)](移除链表元素.md),
18 | 但之前做的题目的参数包括链表本身,以及要删除的目标元素,可以通过迭代链表,通过前继节点与当前节点两个索引来完成。
19 |
20 | 本题目只知道唯一参数是要被删除的节点。
21 | 我们将要删除节点的 next 节点的值赋值给要删除的节点,转而去删除 next 节点,从而达成目的。
22 |
23 | ```python
24 | 4->5->1->9 node = 5
25 | # node.val = node.next.val
26 | 4->1->1->9
27 | # node.next = node.next.next
28 | 4->1->9
29 | ```
30 |
31 | ```python
32 | def deleteNode(node):
33 | node.val = node.next.val
34 | node.next = node.next.next
35 | ```
36 |
--------------------------------------------------------------------------------
/leetcode_linked_list/反转链表.md:
--------------------------------------------------------------------------------
1 | # 206.反转链表
2 | ## 题目
3 | 反转一个单链表。
4 |
5 | ```python
6 | 输入: 1->2->3->4->5->NULL
7 | 输出: 5->4->3->2->1->NULL
8 | ```
9 |
10 | ## 代码
11 | ##### 双指针
12 | 
13 | * 定义两个指针,cur指向当前节点,prev指向当前节点的前一个节点
14 | * 临时记录当前节点的下一个节点,然后把当前节点的下一个节点指向改为当前节点的前一个节点,这样就完成了两个节点的反转
15 | * prev,和cur向后移动
16 |
17 | ```python
18 | def reverseList(head):
19 | prev = None
20 | cur = head
21 | while cur:
22 | tmp = cur.next
23 | cur.next = prev
24 | prev = cur
25 | cur = tmp
26 | return prev
27 | ```
28 |
--------------------------------------------------------------------------------
/leetcode_linked_list/回文链表.md:
--------------------------------------------------------------------------------
1 | ## 回文链表
2 | 请判断一个链表是否为回文链表。
3 | #### 示例
4 | ```python
5 | 输入: 1->2->2->1
6 | 输出: true
7 | 输入: 1->2
8 | 输出: false
9 | ```
10 |
11 | #### 代码
12 | 把链表转成列表,通过列表判断是否回文
13 | ```python
14 | def isPalindrome(head):
15 | val_list = []
16 | cur = head
17 | while cur:
18 | val_list.append(cur.val)
19 | cur = cur.next
20 | return val_list == val_list[::-1]
21 | ```
22 |
--------------------------------------------------------------------------------
/leetcode_linked_list/移除链表元素.md:
--------------------------------------------------------------------------------
1 | # 203.移除链表元素
2 | 删除链表中等于给定值 val 的所有节点。
3 | #### 示例
4 | ```python
5 | 输入: 1->2->6->3->4->5->6, val = 6
6 | 输出: 1->2->3->4->5
7 | ```
8 |
9 | #### 分析
10 | * 添加虚拟头结点,然后从头部开始遍历链表
11 | * 如果当前节点下一个节点值为目标值,就将当前节点的下一个节点指向下下个节点
12 | * 如果当前节点的下一个节点不是目标值,就将下一个节点作为当前节点
13 |
14 | 
15 | 
16 |
17 | ```python
18 | class ListNode:
19 | def __init__(self, x):
20 | self.val = x
21 | self.next = None
22 |
23 | def __str__(self):
24 | vals = [str(self.val)]
25 | next_node = self.next
26 | while next_node:
27 | vals.append(str(next_node.val))
28 | next_node = next_node.next
29 | return '->'.join(vals)
30 |
31 |
32 | def removeElements(head, val):
33 | start = ListNode(0) # 虚拟头结点
34 | cur_node = start
35 | cur_node.next = head
36 | while cur_node.next:
37 | if cur_node.next.val == val:
38 | cur_node.next = cur_node.next.next
39 | else:
40 | cur_node = cur_node.next
41 | return start.next
42 | ```
43 |
--------------------------------------------------------------------------------
/leetcode_linked_list/链表的中间结点.md:
--------------------------------------------------------------------------------
1 | ## 链表的中间结点
2 | 给定一个头结点为 head 的非空单链表,返回链表的中间结点。
3 |
4 | 如果有两个中间结点,则返回第二个中间结点。
5 |
6 | #### 示例
7 | ```python
8 | 输入:[1,2,3,4,5]
9 | 输出:此列表中的结点 3 (序列化形式:[3,4,5])
10 | 返回的结点值为 3 。 (测评系统对该结点序列化表述是 [3,4,5])。
11 | 注意,我们返回了一个 ListNode 类型的对象 ans,这样:
12 | ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, 以及 ans.next.next.next = NULL.
13 | ```
14 |
15 | #### 代码
16 | **两次遍历**
17 |
18 | * 第一次遍历链表,得到链表长度,计算中间节点的位置
19 | * 第二次遍历链表,到中间节点就返回
20 |
21 | ```python
22 | def middleNode(self, head: ListNode) -> ListNode:
23 | count = 0
24 | cur = head
25 | while cur:
26 | count += 1
27 | cur = cur.next
28 |
29 | mid = int(count/2 + 1)
30 |
31 | count = 0
32 | cur = head
33 | while cur:
34 | count += 1
35 | if count == mid:
36 | return cur
37 | cur = cur.next
38 | ```
39 |
40 | **一次遍历**
41 | ```python
42 | def middleNode(head):
43 | A = [head]
44 | while A[-1].next:
45 | A.append(A[-1].next)
46 | mid = len(A)//2
47 | return A[mid]
48 | ```
49 |
50 | **快慢指针**
51 | 用两个指针slow与fast一起遍历链表。slow 一次走一步,fast一次走两步。那么当fast到达链表的末尾时,slow必然位于中间。
52 |
53 | ```python
54 | def middleNode(head):
55 | slow = head
56 | fast = head
57 | while fast and fast.next:
58 | slow = slow.next
59 | fast = fast.next.next
60 | return slow
61 | ```
62 |
--------------------------------------------------------------------------------
/leetcode_stack/main.md:
--------------------------------------------------------------------------------
1 | # LeetCode栈与队列
2 | ## 1.定义
3 | #### 队列
4 | 队列是一种先进先出的线性表(FIFO:First In First Out),它只允许在表的前端进行删除操作,在表的后端进行插入操作。
5 |
6 | 
7 |
8 | #### 栈
9 | 栈是一种后进先出的线性表(LIFO:Last In First Out),它只允许在表尾部进行插入和删除操作。
10 |
11 | 
12 |
13 | ## 2.题目
14 | * [有效的括号](有效的括号.md)
15 | * [用栈实现队列](用栈实现队列.md)
16 | * [用队列实现栈](用队列实现栈.md)
17 | * [删除字符串中的所有相邻重复项](删除字符串中的所有相邻重复项.md)
18 | * [逆波兰表达式求值](逆波兰表达式求值.md)
19 | * [滑动窗口最大值(困难)](滑动窗口最大值.md)
20 | * [前K个高频元素](前K个高频元素.md)
21 |
22 |
35 |
--------------------------------------------------------------------------------
/leetcode_stack/删除字符串中的所有相邻重复项.md:
--------------------------------------------------------------------------------
1 | # 1047.删除字符串中的所有相邻重复项
2 | ## 题目
3 | 给出由小写字母组成的字符串 S,重复项删除操作会选择两个相邻且相同的字母,并删除它们。
4 |
5 | 在 S 上反复执行重复项删除操作,直到无法继续删除。
6 |
7 | 在完成所有重复项删除操作后返回最终的字符串。答案保证唯一。
8 |
9 | 示例:
10 | ```python
11 | 输入:"abbaca"
12 | 输出:"ca"
13 | 解释:
14 | 例如,在 "abbaca" 中,我们可以删除 "bb" 由于两字母相邻且相同,这是此时唯一可以执行删除操作的重复项。之后我们得到字符串 "aaca",其中又只有 "aa" 可以执行重复项删除操作,所以最后的字符串为 "ca"。
15 | ```
16 |
17 | ## 分析
18 | 
19 |
20 | * 利用栈后进先出特性
21 | * 遍历字符串,如果栈为空就入栈,如果栈不为空,比较栈顶元素与当前元素,如果相同就弹栈,不相同就入栈
22 |
23 | ```python
24 | def removeDuplicates(S):
25 | stack = []
26 | for char in S:
27 | if not stack:
28 | stack.append(char)
29 | continue
30 | if stack[-1] == char:
31 | # 弹栈
32 | stack.pop()
33 | continue
34 | stack.append(char)
35 | return ''.join(stack)
36 | ```
37 |
--------------------------------------------------------------------------------
/leetcode_stack/删除最外层的括号.md:
--------------------------------------------------------------------------------
1 | ## 删除最外层的括号
2 | 有效括号字符串为空 ("")、"(" + A + ")" 或 A + B,其中 A 和 B 都是有效的括号字符串,+ 代表字符串的连接。例如,"","()","(())()" 和 "(()(()))" 都是有效的括号字符串。
3 |
4 | 如果有效字符串 S 非空,且不存在将其拆分为 S = A+B 的方法,我们称其为原语(primitive),其中 A 和 B 都是非空有效括号字符串。
5 |
6 | 给出一个非空有效字符串 S,考虑将其进行原语化分解,使得:S = P_1 + P_2 + ... + P_k,其中 P_i 是有效括号字符串原语。
7 |
8 | 对 S 进行原语化分解,删除分解中每个原语字符串的最外层括号,返回 S 。
9 |
10 | 示例:
11 | ```python
12 | 输入:"(()())(())"
13 | 输出:"()()()"
14 | 解释:
15 | 输入字符串为 "(()())(())",原语化分解得到 "(()())" + "(())",
16 | 删除每个部分中的最外层括号后得到 "()()" + "()" = "()()()"。
17 | ```
18 |
19 | 代码:
20 | 遍历字符串
21 |
22 | * 左括号入栈:若入栈后栈的长度大于1,即该左括号不是原语首个左括号,结果加入'('
23 | * 右括号出栈:若出栈后栈的长度大于0,即该右括号不是原语末个右括号,结果加入')'
24 |
25 | ```python
26 | def removeOuterParentheses(S):
27 | stack = []
28 | result = ''
29 | for i in S:
30 | if i == '(':
31 | stack.append(i)
32 | if len(stack) > 1:
33 | result += '('
34 | else:
35 | stack.pop()
36 | if len(stack) != 0:
37 | result += ')'
38 | return result
39 | ```
40 |
--------------------------------------------------------------------------------
/leetcode_stack/前K个高频元素.md:
--------------------------------------------------------------------------------
1 | # 347.前K个高频元素
2 | ## 题目
3 | 给定一个非空的整数数组,返回其中出现频率前 k 高的元素。
4 | ```python
5 | 输入: nums = [1,1,1,2,2,3], k = 2
6 | 输出: [1,2]
7 | ```
8 |
9 | ## 分析
10 | * 统计每个数字出现的次数
11 | * 排序
12 |
13 | ```python
14 | def topKFrequent(nums, k):
15 | times_dict = {}
16 | for num in nums:
17 | times_dict[num] = times_dict.get(num, 0) + 1
18 |
19 | res_list = sorted(times_dict.items(), key=lambda x:x[1], reverse=True)
20 | ans = []
21 | for i in range(0, k):
22 | ans.append(res_list[i][0])
23 | return ans
24 | ```
25 |
--------------------------------------------------------------------------------
/leetcode_stack/整理字符串.md:
--------------------------------------------------------------------------------
1 | ## 整理字符串
2 | 给你一个由大小写英文字母组成的字符串 s 。
3 |
4 | 一个整理好的字符串中,两个相邻字符 s[i] 和 s[i+1],其中 0<= i <= s.length-2 ,要满足如下条件:
5 | * 若 s[i] 是小写字符,则 s[i+1] 不可以是相同的大写字符。
6 | * 若 s[i] 是大写字符,则 s[i+1] 不可以是相同的小写字符。
7 |
8 | 请你将字符串整理好,每次你都可以从字符串中选出满足上述条件的 两个相邻 字符并删除,直到字符串整理好为止。
9 |
10 | 请返回整理好的 字符串 。题目保证在给出的约束条件下,测试样例对应的答案是唯一的。
11 |
12 | 注意:空字符串也属于整理好的字符串,尽管其中没有任何字符。
13 |
14 | #### 示例:
15 | ```python
16 | 输入:s = "leEeetcode"
17 | 输出:"leetcode"
18 | 解释:无论你第一次选的是 i = 1 还是 i = 2,都会使 "leEeetcode" 缩减为 "leetcode" 。
19 |
20 | 输入:s = "abBAcC"
21 | 输出:""
22 | ```
23 |
24 | #### 代码:
25 | ```python
26 | def makeGood(s):
27 | stack = []
28 | for item in s:
29 | if not stack:
30 | stack.append(item)
31 | continue
32 |
33 | while stack:
34 | ele = stack.pop()
35 | if ord(ele) - ord(item) == 32 or ord(item) - ord(ele) == 32:
36 | break
37 | else:
38 | stack.append(ele)
39 | stack.append(item)
40 | break
41 |
42 | return ''.join(stack)
43 | ```
44 |
--------------------------------------------------------------------------------
/leetcode_stack/文件夹操作日志搜集器.md:
--------------------------------------------------------------------------------
1 | ## 文件夹操作日志搜集器
2 | 每当用户执行变更文件夹操作时,LeetCode 文件系统都会保存一条日志记录。
3 | 下面给出对变更操作的说明:
4 | * "../" :移动到当前文件夹的父文件夹。如果已经在主文件夹下,则 继续停留在当前文件夹 。
5 | * "./" :继续停留在当前文件夹。
6 | * "x/" :移动到名为 x 的子文件夹中。题目数据 保证总是存在文件夹 x 。
7 | 给你一个字符串列表 logs ,其中 logs[i] 是用户在 ith 步执行的操作。
8 |
9 | 文件系统启动时位于主文件夹,然后执行 logs 中的操作。
10 |
11 | 执行完所有变更文件夹操作后,请你找出 返回主文件夹所需的最小步数 。
12 |
13 | 示例:
14 | ```python
15 | 输入:logs = ["d1/","../","../","../"]
16 | 输出:0
17 | ```
18 |
19 | #### 代码
20 | ```python
21 | def minOperations(logs):
22 | stack = []
23 | for item in logs:
24 | if item == '../':
25 | if stack:
26 | stack.pop()
27 | elif item == './':
28 | pass
29 | else:
30 | stack.append(item)
31 | return len(stack)
32 | ```
33 |
--------------------------------------------------------------------------------
/leetcode_stack/最小栈.md:
--------------------------------------------------------------------------------
1 | ### 最小栈
2 |
3 | 设计一个支持 push ,pop ,top 操作,并能在常数时间内检索到最小元素的栈。
4 |
5 | * push(x) —— 将元素 x 推入栈中。
6 | * pop() —— 删除栈顶的元素。
7 | * top() —— 获取栈顶元素。
8 | * getMin() —— 检索栈中的最小元素。
9 | * pop、top 和 getMin 操作总是在 非空栈 上调用。
10 |
11 | ```python
12 | class MinStack:
13 |
14 | def __init__(self):
15 | """
16 | initialize your data structure here.
17 | """
18 | self.stack = list()
19 | self.min = None
20 |
21 | def push(self, x: int) -> None:
22 | if self.min is None:
23 | self.min = x
24 | else:
25 | self.min = min(self.min, x)
26 | self.stack.append(x)
27 |
28 | def pop(self) -> None:
29 | self.stack.pop()
30 | if self.stack:
31 | self.min = min(self.stack)
32 | else:
33 | self.min = None
34 |
35 | def top(self) -> int:
36 | return self.stack[-1]
37 |
38 | def getMin(self) -> int:
39 | return self.min
40 | ```
41 |
--------------------------------------------------------------------------------
/leetcode_stack/有效的括号.md:
--------------------------------------------------------------------------------
1 | # 20.有效的括号
2 | ## 题目
3 | 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。
4 |
5 | 有效字符串需满足:
6 |
7 | 左括号必须用相同类型的右括号闭合。
8 | 左括号必须以正确的顺序闭合。
9 | 注意空字符串可被认为是有效字符串。
10 |
11 | ```python
12 | 输入: "()"
13 | 输出: true
14 |
15 | 输入: "()[]{}"
16 | 输出: true
17 |
18 | 输入: "([)]"
19 | 输出: false
20 | ```
21 |
22 | ## 分析
23 | #### 方法一:
24 | 利用字符串替换的方法,如果该字符串是有效字符串,最终总能被替换为空字符串。
25 |
26 | ```python
27 | def isValid(s):
28 | while '()' in s or '[]' in s or '{}' in s:
29 | s = s.replace('()', '').replace('[]', '').replace('{}', '')
30 | return not s
31 | ```
32 |
33 | #### 方法二:
34 | * 每次遇到左括号,就入栈
35 | * 遇到右括号,如果是有效字符串,此时栈的最后一个元素肯定与该右括号匹配。
36 | * 把已经匹配的字符,从栈中弹出
37 |
38 | ```python
39 | def isValid(s):
40 | stack = []
41 | for char in s:
42 | if char not in ['(', '{', '[']:
43 | # 碰到右括号就弹栈
44 | if not stack:
45 | return False
46 |
47 | if (stack[-1] + char) not in ('()', '{}', '[]'):
48 | return False
49 |
50 | stack.pop()
51 | else:
52 | # 碰到左括号就入栈
53 | stack.append(char)
54 |
55 | return not stack
56 | ```
57 |
--------------------------------------------------------------------------------
/leetcode_stack/棒球比赛.md:
--------------------------------------------------------------------------------
1 | ## 棒球比赛
2 |
3 | 你现在是一场采特殊赛制棒球比赛的记录员。这场比赛由若干回合组成,过去几回合的得分可能会影响以后几回合的得分。
4 |
5 | 比赛开始时,记录是空白的。你会得到一个记录操作的字符串列表 ops,其中 ops[i] 是你需要记录的第 i 项操作,ops 遵循下述规则:
6 |
7 | * 整数 x - 表示本回合新获得分数 x
8 | * \+ 表示本回合新获得的得分是前两次得分的总和。题目数据保证记录此操作时前面总是存在两个有效的分数。
9 | * "D" - 表示本回合新获得的得分是前一次得分的两倍。题目数据保证记录此操作时前面总是存在一个有效的分数。
10 | * "C" - 表示前一次得分无效,将其从记录中移除。题目数据保证记录此操作时前面总是存在一个有效的分数。
11 | * 请你返回记录中所有得分的总和。
12 |
13 | 示例:
14 | ```python
15 | 输入:ops = ["5","2","C","D","+"]
16 | 输出:30
17 | 解释:
18 | "5" - 记录加 5 ,记录现在是 [5]
19 | "2" - 记录加 2 ,记录现在是 [5, 2]
20 | "C" - 使前一次得分的记录无效并将其移除,记录现在是 [5].
21 | "D" - 记录加 2 * 5 = 10 ,记录现在是 [5, 10].
22 | "+" - 记录加 5 + 10 = 15 ,记录现在是 [5, 10, 15].
23 | 所有得分的总和 5 + 10 + 15 = 30
24 | ```
25 |
26 | 代码:
27 | * 碰到数字字符串就入栈
28 | * 碰到 "+" "C" "D"就弹栈,计算之后,再把数据入栈
29 |
30 | ```python
31 | def calPoints(ops):
32 | res = []
33 | for item in ops:
34 | if item not in ['+', 'D', 'C']:
35 | res.append(int(item))
36 |
37 | if item == '+':
38 | tmp1 = res.pop()
39 | tmp2 = res.pop()
40 | res.append(tmp2)
41 | res.append(tmp1)
42 | res.append(tmp2 + tmp1)
43 |
44 | if item == 'D':
45 | tmp1 = res.pop()
46 | res.append(tmp1)
47 | res.append(tmp1 * 2)
48 |
49 | if item == 'C':
50 | res.pop()
51 | return sum(res)
52 | ```
53 |
--------------------------------------------------------------------------------
/leetcode_stack/比较含退格的字符串.md:
--------------------------------------------------------------------------------
1 | ## 比较含退格的字符串
2 | 给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果。 # 代表退格字符。
3 |
4 | 注意:如果对空文本输入退格字符,文本继续为空。
5 |
6 | 示例:
7 | ```python
8 | 输入:S = "ab#c", T = "ad#c"
9 | 输出:true
10 | 解释:S 和 T 都会变成 “ac”。
11 | ```
12 |
13 | 代码:
14 | * 碰到“#”就弹栈
15 | * 碰到其他字符就入栈
16 |
17 | ```python
18 | def backspaceCompare(S, T):
19 | s_stack = []
20 | t_stack = []
21 | for item in S:
22 | if item == '#' and s_stack:
23 | s_stack.pop()
24 | if item != '#':
25 | s_stack.append(item)
26 |
27 | for item in T:
28 | if item == '#' and t_stack:
29 | t_stack.pop()
30 | if item != '#':
31 | t_stack.append(item)
32 |
33 | return s_stack == t_stack
34 | ```
35 |
--------------------------------------------------------------------------------
/leetcode_stack/用栈实现队列.md:
--------------------------------------------------------------------------------
1 | # 232.用栈实现队列
2 | ## 题目
3 | 请你仅使用两个栈实现先入先出队列。队列应当支持一般队列的支持的所有操作(push、pop、peek、empty):
4 |
5 | 实现 MyQueue 类:
6 |
7 | * void push(int x) 将元素 x 推到队列的末尾
8 | * int pop() 从队列的开头移除并返回元素
9 | * int peek() 返回队列开头的元素
10 | * boolean empty() 如果队列为空,返回 true ;否则,返回 false
11 |
12 |
13 | ## 代码
14 | * 用两个列表模拟栈,只能后进先出
15 | * 队列先进先出,入队顺序1,2,3,4, 出队顺序也是1,2,3,4
16 | * 入栈,入栈顺序 1,2,3,4, 出栈顺序4,3,2,1
17 | * 出栈,入栈顺序,4,3,2,1, 出栈顺序1,2,3,4,
18 | * 正好两个栈的顺序结合效果等于队列的顺序
19 |
20 | 
21 |
22 | ```python
23 | class MyQueue:
24 |
25 | def __init__(self):
26 | self.stack_in = [] # 入栈
27 | self.stack_out = [] # 出栈
28 |
29 | def push(self, x: int) -> None:
30 | # 往队列中添加元素
31 | self.stack_in.append(x)
32 |
33 | def pop(self) -> int:
34 | # 从队列中取出一个元素
35 | if not self.stack_out:
36 | self.stack_out = self.stack_in[::-1]
37 | self.stack_in = []
38 | return self.stack_out.pop()
39 |
40 | def peek(self) -> int:
41 | # 获取队列的头部
42 | if not self.stack_out:
43 | self.stack_out = self.stack_in[::-1]
44 | self.stack_in = []
45 | return self.stack_out[-1]
46 |
47 | def empty(self) -> bool:
48 | # 判断队列是否为空
49 | if self.stack_out or self.stack_in:
50 | return False
51 | return True
52 | ```
53 |
--------------------------------------------------------------------------------
/leetcode_stack/用队列实现栈.md:
--------------------------------------------------------------------------------
1 | # 225.用队列实现栈
2 | ## 题目
3 | 使用队列实现栈的下列操作:
4 | * push(x) -- 元素 x 入栈
5 | * pop() -- 移除栈顶元素
6 | * top() -- 获取栈顶元素
7 | * empty() -- 返回栈是否为空
8 |
9 | ## 代码
10 | * 队列先进先出
11 | * 栈后进先出
12 | * 一个队列在模拟栈弹出元素的时候只要将队列头部的元素(除了最后一个元素外) 重新添加到队列尾部,此时在去弹出元素就是栈的顺序了
13 |
14 | 
15 |
16 | ```python
17 | from queue import Queue
18 |
19 | class MyStack:
20 |
21 | def __init__(self):
22 | self.stack = Queue()
23 | self.top_ele = None
24 |
25 |
26 | def push(self, x: int) -> None:
27 | # 入栈
28 | self.stack.put(x)
29 | self.top_ele = x
30 |
31 |
32 | def pop(self) -> int:
33 | # 弹栈
34 | size = self.stack.qsize()
35 | while size > 1:
36 | ele = self.stack.get()
37 | self.stack.put(ele)
38 | self.top_ele = ele
39 | size -= 1
40 | result = self.stack.get()
41 | return result
42 |
43 |
44 | def top(self) -> int:
45 | # 获取栈顶元素
46 | return self.top_ele
47 |
48 |
49 | def empty(self) -> bool:
50 | # 栈是否为空
51 | if self.stack.qsize():
52 | return False
53 | return True
54 | ```
55 |
--------------------------------------------------------------------------------
/leetcode_stack/逆波兰表达式求值.md:
--------------------------------------------------------------------------------
1 | # 150.逆波兰表达式求值
2 | ## 题目
3 | 根据 逆波兰表示法,求表达式的值。
4 |
5 | 有效的算符包括 +、-、*、/ 。每个运算对象可以是整数,也可以是另一个逆波兰表达式。
6 | * 整数除法只保留整数部分。
7 | * 给定逆波兰表达式总是有效的。换句话说,表达式总会得出有效数值且不存在除数为 0 的情况。
8 |
9 | ```python
10 | 输入:tokens = ["2","1","+","3","*"]
11 | 输出:9
12 | 解释:该算式转化为常见的中缀算术表达式为:((2 + 1) * 3) = 9
13 | ```
14 |
15 | #### 逆波兰表达式:
16 | 逆波兰表达式是一种后缀表达式,所谓后缀就是指算符写在后面。
17 | * 平常使用的算式则是一种中缀表达式,如 ( 1 + 2 ) * ( 3 + 4 ) 。
18 | * 该算式的逆波兰表达式写法为 ( ( 1 2 + ) ( 3 4 + ) * ) 。
19 |
20 | ## 分析
21 | * 利用栈,碰到数字就入栈,碰到运算符号就从栈顶弹出两个元素进行运算,并将计算结果入栈
22 |
23 | 
24 |
25 | ```python
26 | def evalRPN(tokens):
27 | stack = []
28 | operator = {'+', '-', '*', '/'}
29 | for char in tokens:
30 | if char not in operator:
31 | stack.append(int(char))
32 | continue
33 | num_2 = stack.pop()
34 | num_1 = stack.pop()
35 | if char == '+':
36 | res = num_1 + num_2
37 | elif char == '-':
38 | res = num_1 - num_2
39 | elif char == '*':
40 | res = num_1 * num_2
41 | else:
42 | res = int(num_1 / num_2)
43 | stack.append(res)
44 | return stack[0]
45 | ```
46 |
--------------------------------------------------------------------------------
/leetcode_tree/二叉树的中序遍历.md:
--------------------------------------------------------------------------------
1 | # 94.二叉树的中序遍历
2 | ## 题目
3 | 给定一个二叉树的根节点 root ,返回它的 中序 遍历。
4 |
5 | ## 分析
6 | #### 递归
7 | 中序遍历是按照 左子树-根节点-右子树的方式遍历 ,在访问左子树或右子树的时候,也是同样的方式遍历
8 |
9 | ```python
10 | class TreeNode:
11 | def __init__(self, val=0, left=None, right=None):
12 | self.val = val
13 | self.left = left
14 | self.right = right
15 |
16 |
17 | def inorderTraversal(root):
18 | def inorder(root):
19 | if not root:
20 | return
21 | inorder(root.left)
22 | ans.append(root.val)
23 | inorder(root.right)
24 |
25 | ans = list()
26 | inorder(root)
27 | return ans
28 |
29 | if __name__ == '__main__':
30 | root = TreeNode(1)
31 | node_1 = TreeNode(2)
32 | node_2 = TreeNode(3)
33 | root.left = node_1
34 | root.right = node_2
35 |
36 | res = inorderTraversal(root)
37 | print(res)
38 | ```
39 |
40 | #### 迭代
41 | 
42 |
43 | ```python
44 | def inorderTraversal(root):
45 | ans = list()
46 | if not root:
47 | return ans
48 |
49 | stack = []
50 | node = root
51 | while stack or node:
52 | while node:
53 | stack.append(node)
54 | node = node.left
55 | node = stack.pop()
56 | ans.append(node.val)
57 | node = node.right
58 | return ans
59 | ```
60 |
--------------------------------------------------------------------------------
/leetcode_tree/二叉树的前序遍历.md:
--------------------------------------------------------------------------------
1 | # 144.二叉树的前序遍历
2 | ## 题目
3 | 给你二叉树的根节点 root ,返回它节点值的 前序 遍历。
4 |
5 | ## 分析
6 | #### 递归
7 | 前序遍历是按照 根节点-左子树-右子树的方式遍历 ,在访问左子树或右子树的时候,也是同样的方式遍历
8 |
9 | ```python
10 | class TreeNode:
11 | def __init__(self, val=0, left=None, right=None):
12 | self.val = val
13 | self.left = left
14 | self.right = right
15 |
16 |
17 | def preorderTraversal(root):
18 | def preorder(root):
19 | if not root:
20 | return
21 | ans.append(root.val)
22 | preorder(root.left)
23 | preorder(root.right)
24 |
25 | ans = list()
26 | preorder(root)
27 | return ans
28 | ```
29 |
30 | #### 迭代
31 | * 利用栈,每遍历到非空节点,就记录节点的值(根)就入栈,然后继续遍历该节点的左节点(左)
32 | * 如果左节点为空,说明节点的做节点遍历完毕,结束循环,弹栈,开始遍历右节点,重复第一步
33 |
34 | 
35 |
36 | ```python
37 | class TreeNode:
38 | def __init__(self, val=0, left=None, right=None):
39 | self.val = val
40 | self.left = left
41 | self.right = right
42 |
43 |
44 | def preorderTraversal(root):
45 | ans = list()
46 | if not root:
47 | return ans
48 |
49 | stack = []
50 | node = root
51 | while stack or node:
52 | while node:
53 | ans.append(node.val)
54 | stack.append(node)
55 | node = node.left
56 | node = stack.pop()
57 | node = node.right
58 | return ans
59 | ```
60 |
--------------------------------------------------------------------------------
/leetcode_tree/二叉树的后序遍历.md:
--------------------------------------------------------------------------------
1 | # 145.二叉树的后序遍历
2 | ## 题目
3 | 给定一个二叉树,返回它的 后序 遍历。
4 |
5 | ## 分析
6 | #### 递归
7 | ```python
8 | def postorderTraversal(root):
9 | def postorder(root):
10 | if not root:
11 | return
12 | postorder(root.left)
13 | postorder(root.right)
14 | ans.append(root.val)
15 |
16 | ans = list()
17 | postorder(root)
18 | return ans
19 | ```
20 |
21 | ## 迭代
22 | ```python
23 | def postorderTraversal(root):
24 | ans = list()
25 | if not root:
26 | return ans
27 |
28 | stack = []
29 | node = root
30 | prev = None
31 | while stack or node:
32 | while node:
33 | # 遍历左节点
34 | stack.append(node)
35 | node = node.left
36 | node = stack.pop()
37 | if not node.right or node.right == prev:
38 | # 根节点
39 | ans.append(node.val)
40 | prev = node
41 | node = None
42 | else:
43 | # 遍历右节点
44 | stack.append(node)
45 | node = node.right
46 | return ans
47 | ```
48 |
--------------------------------------------------------------------------------
/leetcode_tree/二叉树的层序遍历.md:
--------------------------------------------------------------------------------
1 | # 102.二叉树的层序遍历
2 | ## 题目
3 | 给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。
4 |
5 | ## 分析
6 | * 队列存放当前层所有节点
7 | * 每次拓展下一层的时候,需要将当前队列中所有节点都取出来进行拓展
8 | * 保证每次拓展完时候,队列中存放的都是同一层的所有节点
9 | * 用列表保存每层的元素值
10 |
11 | ```python
12 | from queue import Queue
13 | def levelOrder(root):
14 | ans = list()
15 | if not root:
16 | return ans
17 | q = Queue()
18 | q.put(root)
19 | while q.qsize():
20 | size = q.qsize()
21 | tmp = []
22 | for _ in range(size):
23 | # 取出这一层所有的元素
24 | node = q.get()
25 | if node:
26 | tmp.append(node.val)
27 | if node.left:
28 | q.put(node.left)
29 | if node.right:
30 | q.put(node.right)
31 | if tmp:
32 | ans.append(tmp)
33 | return ans
34 | ```
35 |
--------------------------------------------------------------------------------
/leetcode_tree/二叉树的层次遍历II.md:
--------------------------------------------------------------------------------
1 | ## 二叉树的层次遍历 II
2 | 给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)
3 | #### 示例
4 | ```python
5 | 3
6 | / \
7 | 9 20
8 | / \
9 | 15 7
10 |
11 | 返回其自底向上的层次遍历为:
12 | [
13 | [15,7],
14 | [9,20],
15 | [3]
16 | ]
17 | ```
18 |
19 | #### 代码
20 | 与[二叉树的最大深度](二叉树的最大深度.md)做法相似,遍历二叉树
21 |
22 | 广度优先搜索:
23 | * 队列存放当前层所有节点
24 | * 每次拓展下一层的时候,需要将当前队列中所有节点都取出来进行拓展
25 | * 保证每次拓展完时候,队列中存放的都是当前层的所有节点
26 | * 用列表保存每层的元素值
27 |
28 | ```python
29 | def levelOrderBottom(root):
30 | if not root:
31 | return []
32 | queue_ = Queue()
33 | queue_.put(root)
34 | result = []
35 | while queue_.qsize():
36 | size = queue_.qsize()
37 | vals = [] # 用列表保存每层的节点值
38 | for _ in range(size):
39 | node = queue_.get()
40 | vals.append(node.val)
41 | left = node.left
42 | right = node.right
43 | if left:
44 | queue_.put(left)
45 | if right:
46 | queue_.put(right)
47 | result.append(vals)
48 | result.reverse()
49 | return result
50 | ```
51 |
--------------------------------------------------------------------------------
/leetcode_tree/二叉树的最大深度.md:
--------------------------------------------------------------------------------
1 | # 104.二叉树的最大深度
2 | ## 题目
3 | 给定一个二叉树,找出其最大深度。
4 |
5 | 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
6 |
7 | 叶子节点是指没有子节点的节点。
8 |
9 | #### 示例
10 | 返回它的最大深度 3 。
11 | ```python
12 | 3
13 | / \
14 | 9 20
15 | / \
16 | 15 7
17 | ```
18 |
19 | ## 分析
20 | #### 递归
21 | 递归: 最大深度 = max(左子树最大深度,右子树最大深度) + 1
22 |
23 | ```python
24 | def maxDepth(root):
25 | if not root:
26 | return 0
27 | return 1 + max(maxDepth(root.left), maxDepth(root.right))
28 | ```
29 |
30 | #### 迭代
31 | * 队列存放当前层所有节点
32 | * 每次拓展下一层的时候,需要将当前队列中所有节点都取出来进行拓展
33 | * 保证每次拓展完时候,队列中存放的都是当前层的所有节点
34 | * 用一个变量维护拓展的次数
35 |
36 | ```python
37 | from queue import Queue
38 | def maxDepth(root):
39 | if not root:
40 | return 0
41 | q = Queue()
42 | q.put(root)
43 | ans = 0
44 | while q.qsize():
45 | ans += 1
46 | size = q.qsize()
47 | for _ in range(size):
48 | node = q.get()
49 | if node.left:
50 | q.put(node.left)
51 | if node.right:
52 | q.put(node.right)
53 | return ans
54 | ```
55 |
--------------------------------------------------------------------------------
/leetcode_tree/二叉树的最小深度.md:
--------------------------------------------------------------------------------
1 | # 111.二叉树的最小深度
2 | ## 题目
3 | 给定一个二叉树,找出其最小深度。
4 |
5 | 最小深度是从根节点到最近叶子节点的最短路径上的节点数量。
6 |
7 | **说明:叶子节点是指没有子节点的节点。**
8 |
9 | 
10 | ```python
11 | 输入:root = [3,9,20,null,null,15,7]
12 | 输出:2
13 | ```
14 |
15 | ## 分析
16 | 与[二叉树的最大深度](二叉树的最大深度.md)逻辑一样,只是碰到叶子节点直接返回深度,不再继续向下遍历
17 |
18 | #### 迭代
19 | ```python
20 | from queue import Queue
21 | def minDepth(root):
22 | if not root:
23 | return 0
24 | q = Queue()
25 | q.put(root)
26 | depth = 0
27 | while q.qsize():
28 | depth += 1
29 | size = q.qsize()
30 | for _ in range(size):
31 | node = q.get()
32 | if node.left is None and node.right is None:
33 | return depth
34 | if node.left:
35 | q.put(node.left)
36 | if node.right:
37 | q.put(node.right)
38 | return depth
39 | ```
40 |
--------------------------------------------------------------------------------
/leetcode_tree/反转二叉树.md:
--------------------------------------------------------------------------------
1 | # 226.反转二叉树
2 | ## 题目
3 | 翻转一棵二叉树。
4 | ```python
5 | 输入
6 | 4
7 | / \
8 | 2 7
9 | / \ / \
10 | 1 3 6 9
11 |
12 | 输出
13 | 4
14 | / \
15 | 7 2
16 | / \ / \
17 | 9 6 3 1
18 | ```
19 |
20 | ## 分析
21 | #### 递归
22 | * 新树的左子树,是旧树的右子树的反转树
23 | * 新树的右子树,是旧树的左子树的反转树
24 |
25 | 
26 | ```python
27 | def invertTree(root):
28 | if not root:
29 | return root
30 | left = invertTree(root.right)
31 | right = invertTree(root.left)
32 | root.left = left
33 | root.right = right
34 | return root
35 | ```
36 |
37 | #### 迭代
38 | * 遍历所有节点,交换每个节点的左右节点的位置
39 |
40 | 
41 |
42 | ```python
43 | def invertTree(root):
44 | if not root:
45 | return root
46 | q_ = [root]
47 | while q_:
48 | node = q_.pop()
49 | left = node.left
50 | right = node.right
51 | # 左右两个子节点交换
52 | node.left = right
53 | node.right = left
54 | if node.left:
55 | q_.append(node.left)
56 | if node.right:
57 | q_.append(node.right)
58 | return root
59 | ```
60 |
--------------------------------------------------------------------------------
/leetcode_tree/另一个树的子树.md:
--------------------------------------------------------------------------------
1 | # 572.另一个树的子树
2 | ## 题目
3 | 给定两个非空二叉树 s 和 t,检验 s 中是否包含和 t 具有相同结构和节点值的子树。s 的一个子树包括 s 的一个节点和这个节点的所有子孙。s 也可以看做它自身的一棵子树。
4 | ```python
5 | 给定的树 s:
6 | 3
7 | / \
8 | 4 5
9 | / \
10 | 1 2
11 | 给定的树 t:
12 | 4
13 | / \
14 | 1 2
15 | 返回 true,因为 t 与 s 的一个子树拥有相同的结构和节点值。
16 | ```
17 |
18 | ## 分析
19 | 迭代,遍历s树,如果子树的根节点与t树的根节点相等,再去判断两个数是否相等,[相同的树](相同的树.md)
20 | ```python
21 | from queue import Queue
22 | def isSubtree(s, t):
23 | def isSame(p, q):
24 | if p is None and q is None:
25 | return True
26 | if not p or not q:
27 | return False
28 | if p.val != q.val:
29 | return False
30 | else:
31 | return isSame(p.left, q.left) and isSame(p.right, q.right)
32 |
33 | Q = Queue()
34 | Q.put(s)
35 | while Q.qsize():
36 | node = Q.get()
37 | if node.val == t.val:
38 | if isSame(node, t):
39 | return True
40 | else:
41 | if node.left:
42 | Q.put(node.left)
43 | if node.right:
44 | Q.put(node.right)
45 | else:
46 | if node.left:
47 | Q.put(node.left)
48 | if node.right:
49 | Q.put(node.right)
50 | return False
51 | ```
52 |
--------------------------------------------------------------------------------
/leetcode_tree/完全二叉树的节点个数.md:
--------------------------------------------------------------------------------
1 | # 222.完全二叉树的节点个数
2 | ## 题目
3 | 给你一棵 完全二叉树 的根节点 root ,求出该树的节点个数。
4 |
5 | ## 分析
6 | #### 迭代
7 | 与[二叉树的层序遍历](二叉树的层序遍历.md)逻辑一样,每次碰到一个节点就累加
8 | ```python
9 | from queue import Queue
10 | def countNodes(root):
11 | if not root:
12 | return 0
13 | q = Queue()
14 | q.put(root)
15 | ans = 0
16 | while q.qsize():
17 | size = q.qsize()
18 | for _ in range(size):
19 | node = q.get()
20 | ans += 1
21 | if node.left:
22 | q.put(node.left)
23 | if node.right:
24 | q.put(node.right)
25 | return ans
26 | ```
27 |
28 | #### 递归
29 | ```python
30 | def countNodes(root):
31 | if not root:
32 | return 0
33 | left_nodes = countNodes(root.left)
34 | right_nodes = countNodes(root.right)
35 | return left_nodes + right_nodes + 1
36 | ```
37 |
--------------------------------------------------------------------------------
/leetcode_tree/将有序数组转换为二叉搜索树.md:
--------------------------------------------------------------------------------
1 | ## 将有序数组转换为二叉搜索树
2 | 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。
3 |
4 | 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1。
5 | #### 示例
6 | ```python
7 | 给定有序数组: [-10,-3,0,5,9],
8 |
9 | 一个可能的答案是:[0,-3,9,-10,null,5],它可以表示下面这个高度平衡二叉搜索树:
10 |
11 | 0
12 | / \
13 | -3 9
14 | / /
15 | -10 5
16 | ```
17 |
18 | #### 代码
19 | * 选择列表中间数字作为二叉搜索树的根节点,这样分给左右子树的数字个数相同或只相差1,可以使得树保持平衡。
20 | * 把列表从中间元素分成左右两个列表,分别对应根节点的左子树与右子树
21 | * 递归
22 |
23 | ```python
24 | def sortedArrayToBST(nums):
25 | if not nums:
26 | return
27 |
28 | length = len(nums)
29 | middle = length // 2
30 | root = TreeNode(nums[middle])
31 | left = sortedArrayToBST(nums[:middle])
32 | right = sortedArrayToBST(nums[middle + 1:])
33 | if left:
34 | root.left = left
35 | if right:
36 | root.right = right
37 | return root
38 | ```
39 |
--------------------------------------------------------------------------------
/leetcode_tree/平衡二叉树.md:
--------------------------------------------------------------------------------
1 | # 110.平衡二叉树
2 | ## 题目
3 | 给定一个二叉树,判断它是否是高度平衡的二叉树。一棵高度平衡二叉树定义为:
4 |
5 | **一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1 。**
6 | #### 示例
7 | 
8 | ```python
9 | 输入:root = [3,9,20,null,null,15,7]
10 | 输出:true
11 | ```
12 |
13 | ## 分析
14 | * 左右两个子树的高度差小于等于1
15 | * 平衡二叉树的两个子树也是平衡二叉树
16 |
17 | ```python
18 | def isBalanced(root):
19 | def depth(root):
20 | # 计算树的深度
21 | if not root:
22 | return 0
23 | return 1 + max(depth(root.left), depth(root.right))
24 |
25 | if not root:
26 | return True
27 | left = root.left
28 | right = root.right
29 | return isBalanced(left) and isBalanced(right) and abs(depth(left) - depth(right)) <= 1
30 |
31 | ```
32 |
--------------------------------------------------------------------------------
/leetcode_tree/找树左下角的值.md:
--------------------------------------------------------------------------------
1 | # 513.找树左下角的值
2 | ## 题目
3 | 给定一个二叉树,在树的最后一行找到最左边的值。
4 | ```python
5 | 输入:
6 |
7 | 1
8 | / \
9 | 2 3
10 | / / \
11 | 4 5 6
12 | /
13 | 7
14 |
15 | 输出:
16 | 7
17 | ```
18 |
19 | ## 分析
20 | #### 迭代
21 | 层序遍历,队列中存放的都是同一层的节点,每一层第一个节点就是最左边的节点
22 |
23 | ```python
24 | from queue import Queue
25 | def findBottomLeftValue(root):
26 | q = Queue()
27 | q.put(root)
28 | while q.qsize():
29 | ans = None
30 | size = q.qsize()
31 | for _ in range(size):
32 | node = q.get()
33 | if not ans:
34 | # 记录每一层最左边的节点
35 | ans = node
36 | if node.left:
37 | q.put(node.left)
38 | if node.right:
39 | q.put(node.right)
40 | return ans.val
41 | ```
42 |
--------------------------------------------------------------------------------
/linux/Shell函数.md:
--------------------------------------------------------------------------------
1 | ## Shell函数
2 | ```python
3 | function func {
4 | statements
5 | [return value]
6 | }
7 |
8 | # 调用 Shell 函数时可以给它传递参数,也可以不传递。如果不传递参数,直接给出函数名字
9 | func
10 | # 如果传递参数,那么多个参数之间以空格分隔
11 | name param1 param2 param3
12 | ```
13 |
14 | ```python
15 | #!/bin/bash
16 |
17 | function getsum(){
18 | local sum=0
19 | for var in $*
20 | do
21 | ((sum+=var))
22 | done
23 | return $sum
24 | }
25 |
26 | getsum 1 2 3
27 | echo $?
28 |
29 | ```
30 |
31 | **shell的function只能返回整数值,可以将返回值赋值给一个变量,调用该funciton后,可以通过该变量获取到返回值**
32 |
--------------------------------------------------------------------------------
/linux/Shell数学计算.md:
--------------------------------------------------------------------------------
1 | # Shell数学计算
2 | ## 1.shell数学计算命令
3 | * (( )):用于整数运算,推荐使用
4 | * let:用于整数运算,与(())类似
5 | * $[]: 用于整数运算
6 | * expr: 可用于整数运算,不推荐
7 | * bc: linux下的计算器程序,可处理整数和小数,shell本身只支持整数运算,要计算小数得使用bc计算器
8 | * declare -i: 将变量定义为整数,然后进行数学运算的时候就不会被当做字符串
9 |
10 | ## 2.shell(())
11 | ```python
12 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# ((a=1+3))
13 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# echo $a
14 | 4
15 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# a=$((2*4))
16 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# echo $a
17 | 8
18 | # 1表示真,0表示假
19 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# echo $((a==8))
20 | 1
21 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# echo $((a+10))
22 | 18
23 | ```
24 |
25 | ## 3.let "表达式"
26 | ```python
27 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# let "a=1+1"
28 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# echo $a
29 | 2
30 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# let b=3*4
31 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# echo $b
32 | 12
33 | ```
34 |
35 | ## 4.declare
36 | ```python
37 | # 除了将a,b定义为整数,还必须将c定义为整数,如果不这样做,在执行c=$a+$b时,Shell依然会将a、b视为字符串。
38 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# declare -i a b c
39 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# a=11
40 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# b=12
41 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# c=$a+$b
42 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# echo $c
43 | 23
44 |
45 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# d=$a+$b
46 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# echo $d
47 | 11+12
48 | ```
49 |
--------------------------------------------------------------------------------
/linux/casein语句.md:
--------------------------------------------------------------------------------
1 | ## case in语句
2 | ```python
3 | case expression in
4 | pattern1)
5 | ...
6 | ;;
7 | pattern2)
8 | ...
9 | ;;
10 | pattern3)
11 | ...
12 | ;;
13 | *)
14 | statementn
15 | esac
16 | ```
17 |
18 | ```python
19 | #!/bin/bash
20 |
21 | printf "输入一个整数:"
22 | read num
23 |
24 | case $num in
25 | 1)
26 | echo "Monday"
27 | ;;
28 | 2)
29 | echo "Tuesday"
30 | ;;
31 | 3)
32 | echo "Wednesday"
33 | ;;
34 | 4)
35 | echo "Thursday"
36 | ;;
37 | 5)
38 | echo "Friday"
39 | ;;
40 | 6)
41 | echo "Saturday"
42 | ;;
43 | 7)
44 | echo "Sunday"
45 | ;;
46 | *)
47 | echo "error"
48 | esac
49 |
50 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
51 | 输入一个整数:1
52 | Monday
53 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
54 | 输入一个整数:2
55 | Tuesday
56 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
57 | 输入一个整数:9
58 | error
59 | ```
60 |
--------------------------------------------------------------------------------
/linux/for循环.md:
--------------------------------------------------------------------------------
1 | ## for循环
2 | ```python
3 | for(( 初始化语句; 判断条件; 自增或自减 ))
4 | do
5 | ...
6 | done
7 | ```
8 |
9 | ```python
10 | #!/bin/bash
11 |
12 | sum=0
13 | for ((i=0;i<=100;i++))
14 | do
15 | ((sum+=i))
16 | done
17 |
18 | echo $sum
19 | ```
20 |
21 |
22 | ## python风格的for循环
23 | ```python
24 | items=("item1" "item2" "item3")
25 | for s in ${items[*]}
26 | do
27 | echo "$s"
28 | done
29 |
30 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
31 | item1
32 | item2
33 | item3
34 | ```
35 |
--------------------------------------------------------------------------------
/linux/if语句.md:
--------------------------------------------------------------------------------
1 | # if语句
2 |
3 | ### if
4 | ```python
5 | if condition
6 | then
7 | ....
8 | fi
9 | ```
10 |
11 | ```python
12 | # 示例
13 | #!/bin/bash
14 |
15 | a=3
16 | if (($a>2))
17 | then
18 | echo "a大于2"
19 | fi
20 |
21 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
22 | a大于2
23 | ```
24 |
25 |
26 | ### if else
27 | ```python
28 | if condition
29 | then
30 | ....
31 | else
32 | ....
33 | fi
34 | ```
35 |
36 | ```python
37 | #!/bin/bash
38 |
39 | read -p "请输入a的值: " a
40 | if (($a>=10))
41 | then
42 | echo "a大于等于10"
43 | else
44 | echo "a小于10"
45 | fi
46 |
47 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
48 | 请输入a的值: 5
49 | a小于10
50 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
51 | 请输入a的值: 12
52 | a大于等于10
53 | ```
54 |
55 | ### if elif else
56 | ```python
57 | if condition1
58 | then
59 | ...
60 | elif condition2
61 | then
62 | ...
63 | elif condition3
64 | then
65 | ...
66 | else
67 | ...
68 | fi
69 | ```
70 |
71 | ```python
72 | #!/bin/bash
73 |
74 | read -p "请输入a的值: " a
75 | if (($a>=10))
76 | then
77 | echo "a>=10"
78 | elif (($a>=5))
79 | then
80 | echo "5<=a<10"
81 | else
82 | echo "a<5"
83 | fi
84 |
85 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
86 | 请输入a的值: 3
87 | a<5
88 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
89 | 请输入a的值: 5
90 | 5<=a<10
91 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
92 | 请输入a的值: 12
93 | a>=10
94 | ```
95 |
--------------------------------------------------------------------------------
/linux/main.md:
--------------------------------------------------------------------------------
1 | ## Linux相关
2 | 1. [Linux常用操作命令(更新……)](Linux常用操作命令.md)
3 | 2. [tmux常用操作命令](tmux常用操作命令.md)
4 |
5 | ## Linux基础
6 | 2. [Linux文件属性与权限](Linux文件权限.md)
7 | 3. [Linux文件与目录管理](Linux文件目录管理.md)
8 | 4. [Linux文件系统(索引式文件系统)](Linux文件系统.md)
9 | 5. [Linux文件压缩与打包](Linux文件压缩与打包.md)
10 | 6. [vim编辑器基本操作](vim编辑器基本操作.md)
11 | 7. [数据流重定向与管线命令](数据流重定向与管线命令.md)
12 | 8. [正则表达式](正则表达式.md)
13 | 9. [sed命令与awk命令](sed命令与awk命令.md)
14 |
15 | ## Nginx
16 | 1. [centos7安装nginx](centos7安装nginx.md)
17 | 2. [nginx基本配置与参数说明](nginx基本配置与参数说明.md)
18 |
19 | ## Shell
20 | 1. [Shell变量](Shell变量.md)
21 | 2. [Shell位置参数与特殊变量](Shell位置参数与特殊变量.md)
22 | 3. [Shell字符串](Shell字符串.md)
23 | 4. [Shell数组](Shell数组.md)
24 | 5. [Shell数学计算](Shell数学计算.md)
25 | 6. [Shell if else语句](if语句.md)
26 | 7. [Shell test命令和\[\[\]\]](test命令和[[]].md)
27 | 8. [Shell case in语句](casein语句.md)
28 | 9. [Shell while语句](while语句.md)
29 | 10. [Shell for循环](for循环.md)
30 | 11. [Shell函数](Shell函数.md)
31 | 12. [常用shell脚本](常用shell脚本.md)
32 |
33 |
34 | ## 常用命令
35 | 1. [常用系统工作命令(echo, date, reboot, poweroff, wget, ps, top, pidof, kill, killall, whereis, locate, tar, sync)](Linux常用系统工作命令.md)
36 | 2. [系统状态监测命令(ifconfig, uname, uptime, free, who, last, history)](Linux系统状态监测命令.md)
37 | 3. [目录切换与文本编辑(pwd, cd, ls, cat, more, head, tail, tr, wc, stat, cut, diff)](Linux目录切换与文本编辑.md)
38 | 4. [文件目录管理命令(touch, mkdir, cp, mv, rm, dd, file)](Linux文件目录管理命令.md)
39 |
--------------------------------------------------------------------------------
/linux/nignx_install/nginx-1.18.0.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/linux/nignx_install/nginx-1.18.0.tar.gz
--------------------------------------------------------------------------------
/linux/nignx_install/openssl-1.1.1g.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/linux/nignx_install/openssl-1.1.1g.tar.gz
--------------------------------------------------------------------------------
/linux/nignx_install/pcre-8.44.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/linux/nignx_install/pcre-8.44.tar.gz
--------------------------------------------------------------------------------
/linux/nignx_install/zlib-1.2.11.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/linux/nignx_install/zlib-1.2.11.tar.gz
--------------------------------------------------------------------------------
/linux/tmux常用操作命令.md:
--------------------------------------------------------------------------------
1 | ## tmux 命令
2 | #### 会话 session
3 | * tmux:直接创建一个默认的会话session
4 | * tmux ls: 查看所有的会话,快捷键:ctrl+b s
5 | * tmux new -s session_name: 指定会话名称创建会话
6 | * tmux detach: 离开会话,快捷键:ctrl+b d
7 | * tmux a -t session_name: 进入会话
8 | * tmux kill-session -t session_name: 杀掉会话,快捷键:ctrl+d
9 | * tmux rename-session -t old_name new_name: 重命名session
10 |
11 | #### 窗口 windows
12 | * tmux new-window -n window_name: 新建一个窗口
13 | * **ctrl+b w: 查看所有窗口**
14 | * tmux select-window -t window_name: 切换窗口
15 | * tmux kill-window -t window_name: 关闭窗口,快捷键:ctrl+b & 关闭当前窗口
16 |
17 | #### 窗格 pane
18 | * tmux split-window: 上下切割,快捷键:ctrl+b %
19 | * tmux split-window -h: 左右切割,快捷键:ctrl+b "
20 | * ctrl+b 方向键:切换窗格
21 | * ctrl+b x: 关闭窗格
22 |
23 |
24 |
--------------------------------------------------------------------------------
/linux/while语句.md:
--------------------------------------------------------------------------------
1 | ## while语句
2 | ```python
3 | while condition
4 | do
5 | ...
6 | done
7 | ```
8 |
9 | ```python
10 | #!/bin/bash
11 |
12 | read -p "请输入m:" m
13 | read -p "请输入n:" n
14 |
15 | sum=0
16 | while ((m <= n))
17 | do
18 | ((sum+=m))
19 | ((m++))
20 | done
21 |
22 | echo "sum:$sum"
23 |
24 | [root@iZ8vb6ughzbdqkfd58dowoZ bin]# shell_1.sh
25 | 请输入m:0
26 | 请输入n:9
27 | sum:45
28 | ```
29 |
--------------------------------------------------------------------------------
/network_protocol/HTTP概念.md:
--------------------------------------------------------------------------------
1 | # HTTP概念
2 | ## 1.定义
3 | HTTP,HyperText Transfer Protocol,超文本(文本,图片,视频等)传输协议,是基于TCP协议的应用层传输协议。
4 |
5 | ## 2.HTTP的特性
6 | * 灵活:Http允许传输多种类型的数据对象,传输类型在请求头Content-Type中标记
7 | * 无连接:每次连接只处理一个请求,请求时建立连接,请求后释放连接,尽快将资源释放出来服务其他客户端,但随着网页越来越复杂,里面可能嵌套的很多图片,每次访问图片都需要建立一次TCP连接这样就很低效,后来的Keep-Alive解决这个问题,Keep-Alive 功能使客户端到服务器端的连接持续有效,当出现对服务器的后继请求时,Keep-Alive 功能避免了建立或者重新建立连接。
8 | * 无状态:HTTP协议不记录客户端的状态,客户端的每次请求对服务端来说都是独立的。
9 |
10 | ## 3.URL与URI
11 | * URI:Uniform Resource Identifier,统一资源标识符
12 | * URL:Uniform Resource Locator,统一资源定位符,一段字符串标识资源的定位地址(协议名称+服务器IP+服务器端口+服务器上路径)
13 | * URN:Uniform Resource Name,统一资源名称
14 |
15 | **URI重点是对资源的唯一标识,可以通过地址标识资源(URL),也可以通过唯一名称标识资源(URN).**
16 |
--------------------------------------------------------------------------------
/network_protocol/IP数据报的发送和转发过程.md:
--------------------------------------------------------------------------------
1 | # IP数据报的发送和转发过程
2 | 1. 主机发送IP数据报
3 | 2. 路由器转发IP数据报
4 |
5 | #### 过程
6 | **下图,路由器的接口0直连了一个以太网,接口1直连了一个以太网,每个网络的子网掩码及主机地址如图:**
7 | 
8 |
9 | * 同一个网络中的主机可以直接通信,属于直接交付
10 | * 不同网络之间的通信需要通过路由器,属于间接交付
11 |
12 | #### 1.源主机如何知道目的主机是否与自己在同一个网络中?
13 | * 主机C要与主机F发送IP数据报
14 | * 主机C把自己的IP地址与子网掩码与运算,得到主机C所在网络的网络地址
15 | * 主机C知道主机F的IP地址,同样把主机F的IP地址与自己的子网掩码运算,得到主机F的网络地址
16 | * 两次运算的网络地址不相等,所以主机C判定主机F与自己不在同一个网络
17 | * 所以主机C需要将IP数据报传输给路由器,通过路由器转发
18 |
19 | #### 2.主机C如何把IP数据报交给路由器进行转发?
20 | * 用户为了让本网络中的主机与其他网络的主机进行通信
21 | * 必须给主机指定一个本网络中的路由器地址,由该路由器进行转发,指定的路由器地址也称为“默认网关”
22 | * 所以把路由器接口0的IP地址设置为该接口直连网络中的各个主机的默认网关
23 | 
24 |
25 | #### 3.路由器收到IP数据报后如何转发?
26 | * 路由器会先检查IP数据报首部是否出错,如果出错,会丢弃该IP数据报,并告知源主机;如果没有出错,则进行转发
27 | * 根据IP数据报中的目的地址,在路由表中查找匹配条目,如果找到匹配,就进行转发;如果找不到匹配,就丢弃并告之源主机
28 | * 路由器知道自己的接口对应的网络的网络地址
29 | * 路由器通过目的IP地址与路由表中的子网掩码进行运算,得到目的网络地址与路由表中记录的目的网络地址如果相同,则通过该接口转发数据报
30 | 
31 | 
32 |
33 |
34 | **路由器不转发广播数据报,避免网络风暴。**
35 |
--------------------------------------------------------------------------------
/network_protocol/TCP可靠传输的实现.md:
--------------------------------------------------------------------------------
1 | # TCP可靠传输的实现
2 | **TCP协议是基于以字节为单位的滑动窗口来实现可靠传输的。**
3 |
4 | 1. 如图,接收方发送TCP确认报文段给发送方,rwnd表示自己的接收窗口大小为20,确认号ack=31表示序号31之前的数据都已经正确接收
5 | 
6 |
7 | 2. 发送方收到确认报文段,调整自己的发送窗口
8 | 
9 |
10 | 3. 发送窗口内31-50号的数据都是允许发送的,如图,31-41号数据已发送,还没有收到确认,42-50号数据是允许发送还没有发送的
11 | 
12 |
13 | 4. 如图,接收方接收窗口31号之前的数据是已成功接收并交付的数据,可以从缓存中删除,31-50号数据是等待接收的数据
14 | 5. 发送方此时发送的32-33号数据成功被接收方接收到,并被接收方存入到接收缓存中
15 | 6. 但是32-33号数据是未按序到达的数据,因为此时还没有收到31号数据
16 | 7. **接收方只能对按序收到的数据中的最高序号给出确认**,所以,接收方发出的确认报文段的确认号仍然是ack=31,告知发送方自己还没有收到31号数据
17 | 8. 发送方收到确认报文段后,发现是对31号数据的重复确认,知道接收方收到了未按序到达的数据
18 | 9. 由于是发送方收到的第一个重复确认,所以并不会引起发送方快重传现象(三次连续重复确认才会快重传)
19 | 
20 |
21 | 10. 31号数据到达接收方后,接收方将数据存入接收缓存,此时接收方可以将31-33号数据交付给应用进程,并发送确认报文段ack=34,表示34号之前的数据都已正确接收了
22 | 
23 |
24 | 11. 发送方和接收方调整滑动窗口
25 | 12. 发送方将发送窗口内的数据全部发送,此时,如果没有收到新的确认,发送方将不再发送新数据(流量控制)
26 | 
27 |
28 | 13. 如果接收方迟迟收不到按序到达的数据,会引起发送方超时重传,发送方会将发送窗口内的已发送的数据进行重传,并重新启动计时器
29 | 
30 |
--------------------------------------------------------------------------------
/network_protocol/TCP超时重传时间的选择.md:
--------------------------------------------------------------------------------
1 | # TCP超时重传时间的选择(超时重传时间应略大于加权平均往返时间)
2 | * 往返时间:RTT,TCP数据报文段从发送到收到对应的确认报文段所用的时间
3 | * 超时重传时间RTO
4 | * 如果超时重传时间小于往返时间,会引起TCP报文段不必要的重传,使网络负荷增大
5 | * 如果超时重传时间远大于往返时间,会使网络的空闲时间增大,降低了传输效率
6 |
7 | 
8 |
9 | ## 1.计算加权平均往返时间RTTS
10 | * 但不能直接使用某次测量得到的RTT样本来计算超时重传时间RTO,这样不准确
11 | * 需要利用每次测量得到的RTT样本,计算加权平均往返时间 RTTS
12 | * 加权平均往返时间 RTTS = (1-a)*旧RTTS + a*新的RTT样本, a建议为0.125
13 | * 通过加权平均计算出来的往返时间RTTS比RTT更加平滑,**超时重传时间RTO应略大于加权平均往返时间RTTS**
14 |
15 | ## 2.超时重传时间RTO计算
16 | 
17 |
18 | ## 3.往返时间RTT的测量
19 | * 通过上述公式发现超时重传时间RTO的计算跟往返时间RTT关系密切
20 | * TCP报文段传输丢失后,然后进行超时重传,此时收到对应的TCP确认报文段,但发送方此时无法判断该确认报文段是对原报文段的确认,还是对重传的TCP报文段的确认
21 | * 针对出现超时重传时无法准确测量往返时间的问题,报文段每重传一次,就把超时重传时间RTO的值增大一些,典型做法是将新的RTO的值取值为旧的RTO的两倍
22 |
23 | 
24 |
--------------------------------------------------------------------------------
/network_protocol/main.md:
--------------------------------------------------------------------------------
1 | ## 计算机网络
2 | 针对B站上湖科大教书匠的《计算机网络微课堂》视频所做的学习笔记,很不错的计算机网络教程。
3 | https://www.bilibili.com/video/BV1c4411d7jb?share_source=copy_web
4 |
5 | 1. [电路交换与分组交换](电路交换与分组交换.md)
6 | 2. [计算机网络分类](计算机网络分类.md)
7 | 3. [计算机网络的性能指标](计算机网络的性能指标.md)
8 | 4. [计算机网络的体系结构](计算机网络的体系结构.md)
9 | 5. [物理层与数据链路层](物理层与数据链路层.md)
10 | 6. [MAC地址、IP地址、ARP协议](MAC_IP_ARP.md)
11 | 7. [以太网交换机(二层交换机)](二层交换机.md)
12 | 8. [网络层](网络层.md)
13 | 9. [IP数据报的发送和转发过程](IP数据报的发送和转发过程.md)
14 | 10. [运输层](运输层.md)
15 | 11. [TCP首部](TCP首部.md)
16 | 12. [TCP的流量控制](TCP的流量控制.md)
17 | 13. [TCP的拥塞控制](TCP的拥塞控制.md)
18 | 14. [TCP超时重传时间的选择](TCP超时重传时间的选择.md)
19 | 15. [TCP可靠传输的实现](TCP可靠传输的实现.md)
20 | 16. [TCP连接的建立与释放](TCP连接的建立与释放.md)
21 | 17. [TCP/IP总结](TCPIP总结.md)
22 |
23 | ## HTTP
24 | 1. [HTTP概念](HTTP概念.md)
25 | 2. [HTTP状态码、网关、代理、隧道](状态码网关代理隧道.md)
26 | 3. [HTTP首部字段](http首部字段.md)
27 | 4. [HTTPS原理](HTTPS原理.md)
28 |
29 | * [总结](总结.md)
30 |
--------------------------------------------------------------------------------
/network_protocol/二层交换机.md:
--------------------------------------------------------------------------------
1 | # 二层交换机
2 | * 以太网交换机,因为其工作在数据链路层(第二层),所以也叫二层交换机
3 | * 以太网交换机收到帧后,在自己的缓存表(帧交换表)中查找目的MAC地址对应的接口,然后通过该接口转发给目的主机
4 | * 以太网交换机是即插即用设备,刚启动时帧交换表内部是空的,随着网络内个主机间通信,通过自学习记录逐渐建立起帧交换表
5 |
6 | #### 以太网交换机的转发原理如下:
7 | 
8 |
--------------------------------------------------------------------------------
/network_protocol/数据链路.md:
--------------------------------------------------------------------------------
1 | # 数据链路
2 | ## 一、数据链路层的作用
3 | **数据链路层的协议定义了通过通信媒介(电缆,光纤,电波,红外线等)互联的设备之间传输的规范。**
4 |
5 | **把物理层和数据链路层放在一起来看。计算机是用二进制0和1来表示信息,而实际的通信媒介(电缆,光纤,电波,红外线等)之间处理的是电压的高低,光的闪灭,以及电波的强弱等信号。
6 | 物理层的作用是把这些信号与二进制的0和1进行转换。数据链路层处理的也不说单纯的0和1序列,数据链路层把01集合成一个叫做帧的数据块,然后再进行传输**
7 | ## 二、数据链路相关技术
8 | ### 2.1、关于MAC地址
9 | **MAC地址是用于识别数据链路中互相连接的每一个节点的**。MAC地址长48bit,第3-24位表示厂商识别码,每个NIC厂商都有特定唯一的识别数字,25-48位是厂商内部为识别每一个网卡而用。
10 | 以此保证了世界上不会有相同MAC地址的网卡。MAC常用十六进制表示,如:30-9C-23-1D-25-71
11 | ### 2.2、共享介质型网络
12 | **根据通信介质的使用方式,可以将网络分成共享介质型和非共享介质型**。
13 | **共享介质型网络指多个设备共享同一个通信介质(线路),因此有必要对通信介质进行访问控制,介质访问控制方式有两种:争用方式和令牌传递方式。**
14 | * 争用方式:数据链路上的每个节点(主机)争夺获取数据传输的权利,采用先到先得的方式占用线路发送数据。如果同时发送帧,会出现冲突。
15 | * 令牌传递方式:沿着令牌环发送一种叫做‘令牌’的特殊报文,只有获得令牌的站点(主机)才有权利发送数据。不会发生冲突。
16 |
17 | ### 2.3、非共享介质型网络
18 | **非共享介质型网络是对介质采取专用的一种传输控制方式。这也是以太网的主流方式,通过以太网交换机构建网络,交换机与计算机之间通过端口一对一相连接,从而实现高效的通信。**
19 | ### 2.4、根据MAC地址转发
20 | 根据MAC地址进行转发的设备也就是之前说的二层交换机(网桥),跟据MAC地址转发原理如图:
21 | 
22 | ## 三、以太网
23 | 初期的以太网是多台终端使用同一根电缆的共享介质型网络,现在一般都是用终端与交换机之间独占电缆的方式进行通信(一台电脑一根网线连接交换机)。
24 |
--------------------------------------------------------------------------------
/network_protocol/物理层与数据链路层.md:
--------------------------------------------------------------------------------
1 | # 物理层与数据链路层
2 | ## 1.物理层的基本概念
3 | **物理层考虑的是怎样才能在连接各种计算机的传输介质上传输比特流,物理层为数据链路层屏蔽了各种传输媒体的差异,使数据链路层只需要考虑如何完成本层的协议和服务,而不需要考虑网络的传输媒介是什么。**
4 |
5 | ## 2.数据链路层概述
6 | * 链路:从一个节点到相邻节点的一段物理线路,中间没有任何其他的交换节点。
7 | * 数据链路层以帧为单位,进行数据传输和处理
8 | * 数据链路层实现“封装成帧”,“差错检测”,“可靠传输”
9 |
10 | ## 3.封装成帧
11 | * 封装成帧是指数据链路层对上层(网络层)交付的协议数据单元添加帧头和帧尾,使之成为帧
12 | * 帧头和帧尾包含有重要的控制信息
13 | * 帧头帧尾的作用之一是帧定界,可以使接收方在交付的比特流中提取出一个个帧,进行处理。
14 | * 数据链路层对上层交付的传输数据没有任何限制(如果网络层交付的数据中包含帧定界标志,数据链路层会对其进行转义操作)
15 | * 为了提高帧的传输效率,应当使帧的数据部分长度尽可能大一些,远大于帧头与帧尾
16 | * 最大传输单元MTU:max transfer unit,数据链路层规定的帧的数据部分长度上限
17 |
18 | ## 4.差错检测
19 | * 实际的通信链路并不是理想的,比特在传输过程中可能会出现差错(1变成0,或者0变成1),称为比特差错
20 | * 误码率:在一段时间内,传输错误的比特占传输总比特的比率
21 | * 帧尾有差错检测码,用来检测数据在传输过程中是否产生了比特差错
22 | * 检测码只能检测出帧在传输过程中是否出现了差错,并不能定位错误
23 |
24 | ## 5.可靠传输
25 | * 数据链路向上层提供的服务类型有“可靠传输服务”和“不可靠传输服务”两种
26 | * 一般情况,有线链路的误码率比较低,为了减小开销,不要求数据链路向上层实现可靠传输服务,即使出现了误码,可靠传输问题由其上层处理
27 | * 无线链路容易受到干扰,误码率比较高,因此数据链路层必须向上层提供可靠传输服务
28 | * 比特误差只是传输误差中的一种
29 | * 整个计算机网络体系结构中,传输误差还包括 分组丢失,分组失序,分组重复(出现在网络层)
30 | * 可靠传输服务并不局限于数据链路层
31 |
--------------------------------------------------------------------------------
/network_protocol/电路交换与分组交换.md:
--------------------------------------------------------------------------------
1 | # 电路交换与分组交换
2 | ## 电路交换
3 | **定义:通过电路交换机接通电话线进行通信的方式称为电路交换。**
4 | 过去的电话网,计算机在发送数据时,需要通过电路交换机与目的主机建立一条通信线路,连接建立好之后,发送主机与接收主机可以一直使用这条线路进行数据传输,直到连接断开。
5 |
6 | **电路交换中,两台主机之间的连接电路被占用了,其他计算机进行通信的话就必须等这两台计算机处理结束之后才可以使用这条电路进行通信。**
7 |
8 | #### 电路交换的三个步骤
9 | 1. 建立连接(分配通信资源)
10 | 2. 进行通话(一直占用通信资源)
11 | 3. 释放连接(释放通信资源)
12 |
13 | **优点:独占一条通信线路,有序传输,没有冲突,实时性强**
14 |
15 | **缺点:建立连接的时间太久;独占通信线路,资源利用率低;灵活性差,通信线路中的一个节点出现问题就需要重新建立连接;**
16 |
17 |
18 | ## 分组交换
19 | **定义:计算机将要发送的数据分成多个数据包,按照一定的顺序分别发送,每个数据包的首部都写了发送端和接收端的地址,这样即使是同一条线路,也可以同时为多台计算机提供通信服务,可以明确区分每个分组数据发往的目的地。提高了通信线路的利用率。**
20 |
21 | #### 分组交换优点
22 | * 不需要建立连接,计算机可以随时发送分组
23 | * 线路利用率高
24 | * 加速传输,路由器具有存储和转发的功能,后一个分组的存储操作与前一个分组的转发操作可以同时进行
25 |
26 | #### 分组交换缺点
27 | * 增加了转发时延,分组交换在交换机上需要经过一个存储转发的过程
28 | * 需要传输额外的信息量,除了需要传输的数据之外,每个分组需要添加源地址与目的地址信息
29 | * 存在分组失序,丢失,与重复分组的问题,分组到达目的节点时,需要重新还原成原始报文。
30 |
--------------------------------------------------------------------------------
/network_protocol/网络层.md:
--------------------------------------------------------------------------------
1 | # 网络层
2 | ## 1.网络层提供的是无连接的数据服务(简单灵活,无连接,尽最大努力传输数据报服务)
3 | * 可靠通信应该由用户主机来保证
4 | * 不需要建立网络层连接
5 | * 每个分组可以走不同的路径
6 | * 每个分组的首部必须携带目的主机的完整地址
7 | * 分组可能存在误码,丢失,重复发送的情况
8 | * 网络层不需要提供可靠传输,所以路由器可以做的相对比较简单,价格低廉
9 | * 因特网的设计思想也是将复杂的网络处理功能交给边缘处理(用户主机和运输层),将简单的分组交付功能交付给因特网核心。
10 |
11 | ## 2.IPV4的分类
12 | * A类地址:第1到8位是网络号,首位以二进制0开头,后24位二进制是主机号。
13 | * B类地址:第1到16位是网络号,前两位是二进制10,后16位二进制是主机号。
14 | * C类地址:第1到24位是网络号,前三位是二进制110,后8位二进制是主机号。
15 | * D类地址:第1到32位是网络号,前四位是二进制1110,没有主机号。
16 | * 只有A类,B类,C类地址可以分配分配给网络中的主机或路由器接口
17 | * 主机号全为“0”的是网络地址,不能分配给主机或路由器
18 | * 主机号全为“1”的是广播地址,不能分配给主机或路由器
19 |
20 | 
21 |
22 | #### 2.1. A类地址细节
23 | * A类地址网络号最小是0(00000000,保留不使用),最大是127(01111111,作为本地回测地址,不指派)
24 | * 所以A类地址最后一个可指派的网络号是126
25 | * A类地址可指派的网络数量一共有 126个,(2**(8-1))-2 = 128 -2 = 126
26 | * A类地址每个网络中可分配的IP地址数量 (2**24)-2 = 16777214 (去掉主机号全0和全1的)
27 |
28 | #### 2.2. B类网络
29 | 
30 |
31 | #### 2.3. C类网络
32 | 
33 |
34 | ## 3. 子网的划分与子网掩码
35 | * 除了A,B,C三大类网络地址之外,还可以从主机号中借用一部分作为子网号,从而将这个网络划分为多个子网
36 | * 32比特的子网掩码,可以表示分类IP地址的主机号,分别被借用了几个比特作为子网号
37 | * 子网掩码用连续的比特1对应网络号和子网号,用连续的比特0对应主机号
38 | * IPV4地址与子网掩码进行逻辑与运算,可得到IPV4所在子网的网络地址
39 |
40 | 
41 | 
42 |
--------------------------------------------------------------------------------
/network_protocol/计算机网络分类.md:
--------------------------------------------------------------------------------
1 | # 计算机网络分类
2 | #### 按照交换技术分类
3 | * 电路交换网络
4 | * 分组交换网络
5 |
6 | #### 按使用者分类
7 | * 公用网
8 | * 专用网,如军队,铁路,电力系统的专用网络
9 |
10 | #### 按传输介质分类
11 | * 有线网络
12 | * 无线网络
13 |
14 | #### 按覆盖范围分类
15 | * 广域网 WAN,覆盖范围几十公里到几千公里
16 | * 城域网 MAN,覆盖一个城市
17 | * 局域网 LAN,覆盖一个栋楼或一个校园内
18 | * 个域网 PAN,在个人工作的地方,通过无线网络连接属于个人使用的电子设备
19 |
20 | #### 按拓扑结构分类
21 | * 总线型网络:使用单根传输线把计算机连接起来,优点建网容易,增加节点方便,节省线路;缺点是任意线路出现问题,全网瘫痪。
22 | * 星型网络:每个计算机都有单独的线路与中央节点相连,优点是便于网络的集中控制与管理,缺点是成本较高。
23 | * 环形网络
24 | * 网状型网络:每个节点至少有两条线路与其他节点相连,优点是可靠性高,缺点是控制复杂,线路成本高。
25 |
--------------------------------------------------------------------------------
/network_protocol/计算机网络的性能指标.md:
--------------------------------------------------------------------------------
1 | # 计算机网络的性能指标
2 |
3 | **计算机中数据量的单位是bit,一个bit是一个二进制位,用0或者1表示。**
4 |
5 | * 8 bit = 1 Byte, 一个字节等于8个bit,也就是8个二进制位
6 | * 1 KB = 1024 B,1KB等于2的10次方Byte
7 | * 1 MB = 1024 KB, 1M等于2的10次方KB
8 | * 1 GB = 1024 MB,1G等于2的10次方MB
9 | * 1 TB = 1024 GB,1T等于2的10次方GB
10 |
11 | ## 1.速率
12 | 定义:连接在网络上的主机在数字信道上传送bit的速率,也叫比特率,单位是bit/s,或者bps。
13 | * 1kb/s = 1000bit/s
14 | * 1mb/s = 1000kb/s = 1000 * 1000bit/s
15 |
16 | 例题:有一个待发送的数据块大小为100MB,网卡的发送速率为100Mbps,则网卡发送完数据块要多久?
17 |
18 | ```python
19 | # 全部换算成bit
20 | 100MB = 100 * 1024 * 1024 * 8 bit
21 | 100Mbps = 100 * 1000 * 1000 bit/s
22 | # 相除结果为
23 | 8.388s
24 | ```
25 |
26 | ## 2.带宽
27 | 定义:用来表示网络的通信线路传输数据的能力,在单位时间内,从网络中的某一点到另一点所能通过的“最高数据率”(最大比特量)。
28 | 单位与速率的单位一样,bit/s,Kb/s,Mb/s.
29 |
30 | **通俗理解带宽与速率:**
31 | 一根管子的速率是100Mbps,最大带宽是100Mbps;两根同样的管子,每个管子的传输速率还是100Mbps,但是带宽是200Mbps(单位时间内传输了200M bit单位)。
32 | 速率是物理概念,计算机网络中一般讨论的是带宽。
33 |
34 | ## 3.吞吐量
35 | 定义:单位时间内成功通过某个网络的数据量。吞吐量常用于对现实世界网络的一种测量,以便知道实际上到底有多少数据量能够通过网络。带宽为1Gb/s的网络,通常只能达到700Mb/s,也就是吞吐量是700Mb/s
36 |
37 | ## 4.时延
38 | 网络时延包括有发送时延,传播时延,处理时延。
39 |
40 | ## 5.往返时间RTT(Round-Trip-Time)
41 | 定义:从源主机发送分组数据开始,直到源主机接收到目的主机的确认分组为止所需要的时间。
42 |
--------------------------------------------------------------------------------
/network_protocol/运输层.md:
--------------------------------------------------------------------------------
1 | # 运输层
2 | ## 1.概述
3 | * 物理层,数据链路层,网络层共同解决了网络中各个主机如何连接的问题,实现了主机到主机的通信
4 | * 但实际计算机网络中,进行通信的实体是两端主机中运行的进程,也就是源主机进程与目的主机进程的通信
5 | * 运输层的任务就是:为运行在不同主机上的应用进程提供直接的通信服务
6 | * 根据应用需求不同,运输层为应用层提供两种不同的协议,面向连接的TCP协议,与面向无连接的UDP协议
7 |
8 | ## 2.端口号
9 | * 运行在计算机上的进程使用进程标识符PID表示
10 | * 计算机不同的操作系统,使用不同格式的PID
11 | * 为了使不同操作系统的计算机之间的应用进程可以进行网络通信,就必须使用统一的方法对TCP/IP体系中的应用进程进行标识
12 | * TCP/IP体系使用端口号来区分应用层不同的应用进程
13 | * 端口号使用16bit表示,取值0~65535,0-1023用于常用的应用应用协议,FTP:21 HTTP:80等,1024-49151为没有熟知的应用进程使用,49152-65535给客户端进程选择暂时使用
14 | * 端口号只表示本计算机应用层中各进程
15 |
16 | ## 3.TCP与UDP
17 | #### UDP:用户数据报协议 User Datagram Protocol
18 | * 面向无连接
19 | * 支持一对一,一对多和多对一的交互通信
20 | * 对应用层交付的报文直接打包
21 | * 尽最大努力交付,不可靠传输,不使用流量控制和拥塞控制
22 | * 首部开销小,只占用8字节
23 |
24 | #### TCP:传输控制协议 Transmission Control Protocol
25 | * 面向连接
26 | * 每条TCP连接只能有两个端点,只能是一对一通信
27 | * 面向字节流
28 | * 可靠传输,使用流量控制和拥塞控制
29 | * 首部最小是20字节,最大60字节
30 |
--------------------------------------------------------------------------------
/others/main.md:
--------------------------------------------------------------------------------
1 | ## 其他
2 | 1. [kafka基本概念](kafka基本概念.md)
3 |
4 | 2. [ZeroMQ基础](ZeroMQ基础.md)
5 | 3. [redis基础操作](redis基础操作.md)
6 | 4. [redis基础理论](redis基础理论.md)
7 |
--------------------------------------------------------------------------------
/pic/asyncio1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/asyncio1.png
--------------------------------------------------------------------------------
/pic/bibao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/bibao.png
--------------------------------------------------------------------------------
/pic/conditi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/conditi.png
--------------------------------------------------------------------------------
/pic/data_analysis/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/11.png
--------------------------------------------------------------------------------
/pic/data_analysis/112.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/112.png
--------------------------------------------------------------------------------
/pic/data_analysis/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/2.png
--------------------------------------------------------------------------------
/pic/data_analysis/20180204151140.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/20180204151140.png
--------------------------------------------------------------------------------
/pic/data_analysis/20180204152134.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/20180204152134.png
--------------------------------------------------------------------------------
/pic/data_analysis/20180204152456.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/20180204152456.png
--------------------------------------------------------------------------------
/pic/data_analysis/2EV.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/2EV.png
--------------------------------------------------------------------------------
/pic/data_analysis/bop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/bop.png
--------------------------------------------------------------------------------
/pic/data_analysis/jihe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/jihe.png
--------------------------------------------------------------------------------
/pic/data_analysis/jihep.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/jihep.png
--------------------------------------------------------------------------------
/pic/data_analysis/jihep2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/jihep2.png
--------------------------------------------------------------------------------
/pic/data_analysis/jihep3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/jihep3.png
--------------------------------------------------------------------------------
/pic/data_analysis/jihevar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/jihevar.png
--------------------------------------------------------------------------------
/pic/data_analysis/pailie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/pailie.png
--------------------------------------------------------------------------------
/pic/data_analysis/shijian.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/shijian.png
--------------------------------------------------------------------------------
/pic/data_analysis/zuhe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/data_analysis/zuhe.png
--------------------------------------------------------------------------------
/pic/diguistack.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/diguistack.jpg
--------------------------------------------------------------------------------
/pic/django_note/django1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/django_note/django1.jpg
--------------------------------------------------------------------------------
/pic/django_note/django2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/django_note/django2.jpg
--------------------------------------------------------------------------------
/pic/gitdoc/1_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/1_1.png
--------------------------------------------------------------------------------
/pic/gitdoc/1_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/1_2.png
--------------------------------------------------------------------------------
/pic/gitdoc/1_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/1_3.png
--------------------------------------------------------------------------------
/pic/gitdoc/2_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/2_1.png
--------------------------------------------------------------------------------
/pic/gitdoc/2_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/2_2.png
--------------------------------------------------------------------------------
/pic/gitdoc/2_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/2_3.png
--------------------------------------------------------------------------------
/pic/gitdoc/2_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/2_4.png
--------------------------------------------------------------------------------
/pic/gitdoc/2_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/2_5.png
--------------------------------------------------------------------------------
/pic/gitdoc/2_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/2_6.png
--------------------------------------------------------------------------------
/pic/gitdoc/2_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/2_7.png
--------------------------------------------------------------------------------
/pic/gitdoc/2_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/2_8.png
--------------------------------------------------------------------------------
/pic/gitdoc/2_9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/2_9.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_1_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_1_1.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_1_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_1_2.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_1_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_1_3.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_1_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_1_4.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_1_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_1_5.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_1_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_1_6.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_1_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_1_7.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_2_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_2_1.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_2_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_2_2.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_2_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_2_3.png
--------------------------------------------------------------------------------
/pic/gitdoc/3_2_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/3_2_4.png
--------------------------------------------------------------------------------
/pic/gitdoc/gitbase.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/gitdoc/gitbase.png
--------------------------------------------------------------------------------
/pic/hashtable.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/hashtable.jpg
--------------------------------------------------------------------------------
/pic/htiao.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/htiao.jpg
--------------------------------------------------------------------------------
/pic/jiaocuotiao.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/jiaocuotiao.jpg
--------------------------------------------------------------------------------
/pic/leetcode_array/05_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/05_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_array/15_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/15_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_array/209_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/209_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_array/27_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/27_1.png
--------------------------------------------------------------------------------
/pic/leetcode_array/27_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/27_2.png
--------------------------------------------------------------------------------
/pic/leetcode_array/344_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/344_1.png
--------------------------------------------------------------------------------
/pic/leetcode_array/35_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/35_1.png
--------------------------------------------------------------------------------
/pic/leetcode_array/35_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/35_2.png
--------------------------------------------------------------------------------
/pic/leetcode_array/35_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/35_3.png
--------------------------------------------------------------------------------
/pic/leetcode_array/35_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/35_4.png
--------------------------------------------------------------------------------
/pic/leetcode_array/35_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/35_5.png
--------------------------------------------------------------------------------
/pic/leetcode_array/35_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/35_6.png
--------------------------------------------------------------------------------
/pic/leetcode_array/59_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/59_1.png
--------------------------------------------------------------------------------
/pic/leetcode_array/yanghuisanjiao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_array/yanghuisanjiao.png
--------------------------------------------------------------------------------
/pic/leetcode_hash/202_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_hash/202_1.png
--------------------------------------------------------------------------------
/pic/leetcode_hash/202_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_hash/202_2.png
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/142_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/142_1.png
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/142_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/142_2.png
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/19_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/19_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/19_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/19_1.png
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/19_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/19_2.png
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/203_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/203_1.png
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/203_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/203_2.png
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/206_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/206_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/linkedlist2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/linkedlist2.png
--------------------------------------------------------------------------------
/pic/leetcode_linked_list/linkelist1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_linked_list/linkelist1.png
--------------------------------------------------------------------------------
/pic/leetcode_stack/1047_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_stack/1047_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_stack/150_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_stack/150_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_stack/225_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_stack/225_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_stack/232_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_stack/232_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_stack/239_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_stack/239_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_stack/239_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_stack/239_1.png
--------------------------------------------------------------------------------
/pic/leetcode_stack/duilie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_stack/duilie.png
--------------------------------------------------------------------------------
/pic/leetcode_stack/stack.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_stack/stack.png
--------------------------------------------------------------------------------
/pic/leetcode_tree/101_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/101_1.png
--------------------------------------------------------------------------------
/pic/leetcode_tree/112_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/112_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_tree/112_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/112_1.jpg
--------------------------------------------------------------------------------
/pic/leetcode_tree/144_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/144_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_tree/226_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/226_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_tree/226_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/226_1.png
--------------------------------------------------------------------------------
/pic/leetcode_tree/257_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/257_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_tree/94_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/94_1.gif
--------------------------------------------------------------------------------
/pic/leetcode_tree/balance_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/balance_1.jpg
--------------------------------------------------------------------------------
/pic/leetcode_tree/bianlitree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/bianlitree.png
--------------------------------------------------------------------------------
/pic/leetcode_tree/ex_depth.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/ex_depth.jpg
--------------------------------------------------------------------------------
/pic/leetcode_tree/manerchashu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/manerchashu.png
--------------------------------------------------------------------------------
/pic/leetcode_tree/paixutree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/paixutree.png
--------------------------------------------------------------------------------
/pic/leetcode_tree/wanquantree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/leetcode_tree/wanquantree.png
--------------------------------------------------------------------------------
/pic/linux/fs1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/fs1.png
--------------------------------------------------------------------------------
/pic/linux/fs2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/fs2.png
--------------------------------------------------------------------------------
/pic/linux/linuxcmd_head.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/linuxcmd_head.png
--------------------------------------------------------------------------------
/pic/linux/linuxcmd_locate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/linuxcmd_locate.png
--------------------------------------------------------------------------------
/pic/linux/linuxcmd_ls.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/linuxcmd_ls.png
--------------------------------------------------------------------------------
/pic/linux/linuxcmd_rm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/linuxcmd_rm.png
--------------------------------------------------------------------------------
/pic/linux/linuxcmd_stat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/linuxcmd_stat.png
--------------------------------------------------------------------------------
/pic/linux/linuxqx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/linuxqx.png
--------------------------------------------------------------------------------
/pic/linux/linuxqx2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/linuxqx2.png
--------------------------------------------------------------------------------
/pic/linux/shell1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/shell1.png
--------------------------------------------------------------------------------
/pic/linux/tar1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/linux/tar1.png
--------------------------------------------------------------------------------
/pic/lock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/lock.png
--------------------------------------------------------------------------------
/pic/maoyan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/maoyan.png
--------------------------------------------------------------------------------
/pic/namedtuple.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/namedtuple.jpg
--------------------------------------------------------------------------------
/pic/network_protocol/IPB.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/IPB.png
--------------------------------------------------------------------------------
/pic/network_protocol/IPC.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/IPC.png
--------------------------------------------------------------------------------
/pic/network_protocol/IPfenlei.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/IPfenlei.png
--------------------------------------------------------------------------------
/pic/network_protocol/IPjump.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/IPjump.png
--------------------------------------------------------------------------------
/pic/network_protocol/IProute.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/IProute.png
--------------------------------------------------------------------------------
/pic/network_protocol/L2MAC.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/L2MAC.png
--------------------------------------------------------------------------------
/pic/network_protocol/https_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/https_1.png
--------------------------------------------------------------------------------
/pic/network_protocol/https_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/https_2.png
--------------------------------------------------------------------------------
/pic/network_protocol/https_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/https_3.png
--------------------------------------------------------------------------------
/pic/network_protocol/https_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/https_4.png
--------------------------------------------------------------------------------
/pic/network_protocol/https_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/https_5.png
--------------------------------------------------------------------------------
/pic/network_protocol/https_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/https_6.png
--------------------------------------------------------------------------------
/pic/network_protocol/ipmac.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/ipmac.png
--------------------------------------------------------------------------------
/pic/network_protocol/ipmac2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/ipmac2.png
--------------------------------------------------------------------------------
/pic/network_protocol/ipzhuanfa.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/ipzhuanfa.png
--------------------------------------------------------------------------------
/pic/network_protocol/ipzhuanfa2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/ipzhuanfa2.png
--------------------------------------------------------------------------------
/pic/network_protocol/ipzhuanfa3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/ipzhuanfa3.png
--------------------------------------------------------------------------------
/pic/network_protocol/ipzhuanfa4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/ipzhuanfa4.png
--------------------------------------------------------------------------------
/pic/network_protocol/shuyu1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/shuyu1.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcphead.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcphead.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcphead2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcphead2.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcphead3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcphead3.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpip.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcplianjie1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcplianjie1.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcplianjie2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcplianjie2.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcplianjie3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcplianjie3.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcplianjie4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcplianjie4.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpliuliangkongzhi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpliuliangkongzhi.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpliuliangkongzhi2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpliuliangkongzhi2.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpliuliangkongzhi3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpliuliangkongzhi3.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcprtt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcprtt.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcprtt2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcprtt2.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcprtt3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcprtt3.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpstatus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpstatus.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcptrs1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcptrs1.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcptrs2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcptrs2.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcptrs3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcptrs3.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcptrs4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcptrs4.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcptrs5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcptrs5.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcptrs6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcptrs6.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcptrs7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcptrs7.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpudpport.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpudpport.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpys1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpys1.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpys3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpys3.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpys4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpys4.png
--------------------------------------------------------------------------------
/pic/network_protocol/tcpys5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tcpys5.png
--------------------------------------------------------------------------------
/pic/network_protocol/tongxinshili.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/tongxinshili.png
--------------------------------------------------------------------------------
/pic/network_protocol/ziwangyanma1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/ziwangyanma1.png
--------------------------------------------------------------------------------
/pic/network_protocol/ziwangyanma2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/network_protocol/ziwangyanma2.png
--------------------------------------------------------------------------------
/pic/nginxhttps.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/nginxhttps.jpg
--------------------------------------------------------------------------------
/pic/nginxproxy1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/nginxproxy1.png
--------------------------------------------------------------------------------
/pic/nginxproxy2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/nginxproxy2.png
--------------------------------------------------------------------------------
/pic/nginxproxy5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/nginxproxy5.png
--------------------------------------------------------------------------------
/pic/nginxproxy6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/nginxproxy6.png
--------------------------------------------------------------------------------
/pic/nolock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/nolock.png
--------------------------------------------------------------------------------
/pic/others/chapter1_1zmq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/chapter1_1zmq.png
--------------------------------------------------------------------------------
/pic/others/chapter1_4zmq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/chapter1_4zmq.png
--------------------------------------------------------------------------------
/pic/others/chapter1_5zmq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/chapter1_5zmq.png
--------------------------------------------------------------------------------
/pic/others/kafkafabu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/kafkafabu.png
--------------------------------------------------------------------------------
/pic/others/kafkahanyi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/kafkahanyi.png
--------------------------------------------------------------------------------
/pic/others/kafkaleader.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/kafkaleader.png
--------------------------------------------------------------------------------
/pic/others/kafkaqueue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/kafkaqueue.png
--------------------------------------------------------------------------------
/pic/others/redis_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/redis_1.jpg
--------------------------------------------------------------------------------
/pic/others/zmq_sink.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/zmq_sink.png
--------------------------------------------------------------------------------
/pic/others/zmq_ventilator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/others/zmq_ventilator.png
--------------------------------------------------------------------------------
/pic/pie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/pie.png
--------------------------------------------------------------------------------
/pic/python_advance/download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/python_advance/download.png
--------------------------------------------------------------------------------
/pic/python_advance/gc_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/python_advance/gc_1.png
--------------------------------------------------------------------------------
/pic/python_advance/join.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/python_advance/join.png
--------------------------------------------------------------------------------
/pic/python_advance/setDaemonTrue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/python_advance/setDaemonTrue.png
--------------------------------------------------------------------------------
/pic/python_advance/tcp_client.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/python_advance/tcp_client.png
--------------------------------------------------------------------------------
/pic/python_advance/tcp_server.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/python_advance/tcp_server.png
--------------------------------------------------------------------------------
/pic/python_advance/upload.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/python_advance/upload.png
--------------------------------------------------------------------------------
/pic/python_basic/tuple2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/python_basic/tuple2.png
--------------------------------------------------------------------------------
/pic/python_basic/tuple3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/python_basic/tuple3.png
--------------------------------------------------------------------------------
/pic/redisqueue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/redisqueue.png
--------------------------------------------------------------------------------
/pic/roominfo1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/roominfo1.png
--------------------------------------------------------------------------------
/pic/roominfo2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/roominfo2.png
--------------------------------------------------------------------------------
/pic/roominfo3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/roominfo3.png
--------------------------------------------------------------------------------
/pic/roominfo4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/roominfo4.png
--------------------------------------------------------------------------------
/pic/scrapy1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/scrapy1.png
--------------------------------------------------------------------------------
/pic/scrapy2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/scrapy2.png
--------------------------------------------------------------------------------
/pic/scrapy3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/scrapy3.png
--------------------------------------------------------------------------------
/pic/shunqi1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/shunqi1.png
--------------------------------------------------------------------------------
/pic/shunqi2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/shunqi2.png
--------------------------------------------------------------------------------
/pic/shunqi3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/shunqi3.png
--------------------------------------------------------------------------------
/pic/shunqi4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/shunqi4.png
--------------------------------------------------------------------------------
/pic/spiders/proxypool.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/spiders/proxypool.png
--------------------------------------------------------------------------------
/pic/spiders/zhihu1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/spiders/zhihu1.png
--------------------------------------------------------------------------------
/pic/spiders/zhihu2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/spiders/zhihu2.png
--------------------------------------------------------------------------------
/pic/spiders/zhihu3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/spiders/zhihu3.png
--------------------------------------------------------------------------------
/pic/spiders/zhihu4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/spiders/zhihu4.png
--------------------------------------------------------------------------------
/pic/spiders/zhihu5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/spiders/zhihu5.png
--------------------------------------------------------------------------------
/pic/spiders/zhihu7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/spiders/zhihu7.png
--------------------------------------------------------------------------------
/pic/stack.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/stack.jpg
--------------------------------------------------------------------------------
/pic/taobaores1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/taobaores1.png
--------------------------------------------------------------------------------
/pic/taobaores2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/taobaores2.png
--------------------------------------------------------------------------------
/pic/tcpconn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/tcpconn.png
--------------------------------------------------------------------------------
/pic/threadin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/threadin.png
--------------------------------------------------------------------------------
/pic/toutiaopic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/toutiaopic.png
--------------------------------------------------------------------------------
/pic/tu.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/tu.jpg
--------------------------------------------------------------------------------
/pic/tuple2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/tuple2.png
--------------------------------------------------------------------------------
/pic/vtiao.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/vtiao.jpg
--------------------------------------------------------------------------------
/pic/wangzhan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/wangzhan.png
--------------------------------------------------------------------------------
/pic/wangzhan1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/wangzhan1.png
--------------------------------------------------------------------------------
/pic/wangzhan2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/wangzhan2.png
--------------------------------------------------------------------------------
/pic/wangzhan3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/wangzhan3.png
--------------------------------------------------------------------------------
/pic/weibo1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/weibo1.png
--------------------------------------------------------------------------------
/pic/weibo2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/weibo2.png
--------------------------------------------------------------------------------
/pic/weibo3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/weibo3.png
--------------------------------------------------------------------------------
/pic/weibo4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/weibo4.jpg
--------------------------------------------------------------------------------
/pic/weibo5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/weibo5.jpg
--------------------------------------------------------------------------------
/pic/weixinrequests.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/weixinrequests.png
--------------------------------------------------------------------------------
/pic/weixinspider2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/weixinspider2.png
--------------------------------------------------------------------------------
/pic/xiecheng.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/xiecheng.jpg
--------------------------------------------------------------------------------
/pic/xiecheng.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/xiecheng.png
--------------------------------------------------------------------------------
/pic/yzm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/yzm.png
--------------------------------------------------------------------------------
/pic/zhihu6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/pic/zhihu6.png
--------------------------------------------------------------------------------
/python_advance/MongoDB存储图片.md:
--------------------------------------------------------------------------------
1 | # Python之利用MongoDB存储图片
2 | ## 存入图片到MongoDB数据库
3 |
4 | ```python
5 | from pymongo import MongoClient
6 | from gridfs import *
7 | import os
8 | #连接mongodb
9 | client=MongoClient('localhost',27017)
10 | #取得对应的数据库
11 | db=client.pictures
12 | #取得对应的集合
13 | collection = db.test
14 | #图片路径
15 | img_path = r'C:\Users\daacheng\Desktop\timg.jpg'
16 |
17 | # 数据库其他字段信息
18 | img_info = {
19 | 'content_type': 'jpg',
20 | 'filename': 'timg.jpg',
21 | 'filepath': img_path
22 | }
23 |
24 | with open(img_path, 'rb') as f:
25 | #创建写入流
26 | fs = GridFS(db, collection="test")
27 | data = f.read()
28 | #将数据写入,文件类型和名称通过前面的分割得到
29 | img_id=fs.put(data, **img_info)
30 | print(img_id)
31 | ```
32 |
33 | ## 从MongoDB中下载图片
34 |
35 | ```python
36 | from gridfs import *
37 | from pymongo import MongoClient
38 | from bson.objectid import ObjectId
39 | # 连接数据库
40 | client = MongoClient('localhost', 27017)
41 | db = client['pictures']
42 | fs = GridFS(db, collection='test')
43 | # 通过id查找图片
44 | image_id = '5c2c720381b1bc41ec02eb89'
45 | result = fs.find_one({'_id': ObjectId(image_id)})
46 | data = result.read()
47 | with open('a.jpg', 'wb') as f:
48 | f.write(data)
49 | ```
50 |
--------------------------------------------------------------------------------
/python_advance/main.md:
--------------------------------------------------------------------------------
1 | ## Python进阶
2 | * [Python中的下划线](Python中的下划线.md)
3 | * [可迭代对象、迭代器、生成器](可迭代对象迭代器生成器.md)
4 | * [位置参数、默认参数、可变参数、关键字参数](位置参数默认参数可变参数关键字参数.md)
5 | * [类变量、实例变量、类方法、实例方法、静态方法](类实例静态方法.md)
6 | * [模块和包](模块和包.md)
7 | * [通用日志模块](通用日志模块.md)
8 | * [变量的作用域与闭包](变量的作用域.md)
9 | * [Python命名空间与作用域](命名空间与作用域.md)
10 | * [装饰器](装饰器.md)
11 | * [进程与线程概念](进程与线程概念.md)
12 | * [Python中的多线程](Python中的多线程.md)
13 | * [Python中的多进程](Python中的多进程.md)
14 | * [socket网络编程](socket网络编程.md)
15 | * [Python实现TFTP文件传输](Python实现TFTP文件传输.md)
16 | * [Python连接数据库](Python连接数据库.md)
17 | * [Git基础](Git基础.md)
18 | * [Python之AES加密解密](Python之AES加密解密.md)
19 | * [MongoDB存储图片](MongoDB存储图片.md)
20 | * [python中的协程](python中的协程.md)
21 | * [concurrent.futures模块](concurrentfutures模块.md)
22 | * [Python垃圾回收机制](Python垃圾回收机制.md)
23 | * [Python上下文管理器与with语句](Python上下文管理器与with语句.md)
24 | * [Python实现单例模式](Python实现单例模式.md)
25 | * [Python opencv基础](opencv-python基础.md)
26 |
--------------------------------------------------------------------------------
/python_advance/模块和包.md:
--------------------------------------------------------------------------------
1 | ## 模块和包
2 | * 模块:Python中每个有效的.py文件,就是一个python模块。
3 | * 包:每个包含__init__.py的文件夹,就是一个python包。
4 |
5 | #### \_\_name__
6 | **每个有效的python文件都是一个模块,\_\_name__是标识模块名称的系统变量。**
7 | * 如果模块是被导入的,\_\_name__就是模块名,.py文件的文件名.
8 | * 如果模块是被直接执行的,\_\_name__就是’__main__’
9 |
10 | test1.py
11 |
12 | ```python
13 | def test():
14 | print('__name__ is : ', __name__) # __name__ is : __main__
15 | if __name__ == '__main__':
16 | test()
17 | ```
18 |
19 | test2.py
20 |
21 | ```python
22 | import test1
23 | def test():
24 | print('__name__ is: ', __name__) # __name__ is: __main__
25 | if __name__ == '__main__':
26 | test()
27 | print(test1.test()) # test1
28 | ```
29 |
--------------------------------------------------------------------------------
/python_basic/Python函数参数的传递机制.md:
--------------------------------------------------------------------------------
1 | # Python函数参数的传递机制
2 | ## 不可变对象是值传递
3 | **python中不可变对象,函数实际参数(实参)传递给形式参数(形参)的过程,实际上是把实际参数值的副本(复制品)传入函数,参数本身不会收到任何影响。**
4 |
5 | ```python
6 | def func(a, b):
7 | a, b = b, a
8 | # 函数内 a:2 b:1
9 | print('函数内 a:{} b:{}'.format(a, b))
10 |
11 | if __name__ == '__main__':
12 | a = 1
13 | b = 2
14 | # 可以理解为是将a, b的值复制一份传入
15 | func(a, b)
16 | # 函数外 a:1 b:2
17 | print('函数外 a:{} b:{}'.format(a, b))
18 | ```
19 |
20 | ## 可变对象是引用传递(地址传递)
21 | 对于可变对象如字典,列表等,参数传递的方式是引用传递,也就是将可变对象的引用(内存地址)传递给函数,参数会受到影响。
22 |
23 | ```python
24 | def func(a):
25 | a.append(4)
26 | a.append(5)
27 | # 函数内 a:[1, 2, 3, 4, 5]
28 | print('函数内 a:{}'.format(a))
29 |
30 | if __name__ == '__main__':
31 | a = [1, 2, 3]
32 | func(a)
33 | # 函数内 a:[1, 2, 3, 4, 5]
34 | print('函数外 a:{}'.format(a))
35 | ```
36 |
--------------------------------------------------------------------------------
/python_basic/Python在内存中读写数据.md:
--------------------------------------------------------------------------------
1 | # Python在内存中读写数据
2 | 有时候数据不一定要读写到文件中,可以再内存中进行读写操作。
3 |
4 | 有些场景本地不保存数据,从远程读取文件数据到本地内存中进行处理后,再把数据流推送到远程,从头到尾本地并不生成文件。
5 |
6 | **比如读取服务器一个加密文件数据流到内存中,在内存中进行解析处理,最终将解密后的数据流推送到服务器,中间不需要在本地保存加密文件,直接在内存中处理,减少了IO操作。**
7 | ## StringIO
8 | ```python
9 | from io import StringIO
10 |
11 | if __name__ == '__main__':
12 | s = StringIO()
13 | s.write('123\n')
14 | s.write('456\n')
15 | s.write('aaa\n')
16 | s.write('bbb')
17 | print(s) # <_io.StringIO object at 0x0000022F7440F9D8>
18 | # 获取写入的内容
19 | print(s.getvalue()) # '123\n456\naaa\nbbb'
20 | # tell()方法返回文件指针当前位置
21 | print(s.tell()) # 15
22 |
23 | # seek(offset, whence)方法用于移动文件读取指针到指定位置
24 | # offset:代表需要移动偏移的字节数
25 | # whence:默认0,表示要从哪个位置开始偏移;0代表从文件开头开始算起,1代表从当前位置开始算起,2代表从文件末尾算起。
26 | s.seek(0, 0)
27 |
28 | print(s.tell()) # 0
29 | print(s.readlines()) # ['123\n', '456\n', 'aaa\n', 'bbb']
30 |
31 | print(s.tell()) # 15
32 | print(s.readlines()) # []
33 | ```
34 |
35 | ## BytesIO
36 | ```python
37 | from io import BytesIO
38 |
39 | if __name__ == '__main__':
40 | f = BytesIO()
41 |
42 | fr = open('test.mp4', 'rb')
43 | f.write(fr.read())
44 | fr.close()
45 |
46 | # 对视频流解析处理
47 |
48 | with open('local_test.mp4', 'wb') as fw:
49 | fw.write(f.getvalue())
50 | ```
51 |
--------------------------------------------------------------------------------
/python_basic/Python标准数据类型.md:
--------------------------------------------------------------------------------
1 | # Python标准数据类型
2 | python3中有六种标准数据类型
3 |
4 | * Number:数字,包含int,float,bool,complex(复数)
5 | ```python
6 | # bool型也是数字
7 | print(True + True) # 2
8 | ```
9 | * String:字符串
10 | * List:列表
11 | * Tuple:元组
12 | * Set:集合
13 | * Dict:字典
14 |
15 | ## 可变类型与不可变类型
16 | * 可变类型:在id(内存地址)不变的情况下,值可以变化
17 | * 不可变类型:值一旦发生变化,id(内存地址)也改变,意味着开辟了新的内存空间。
18 | #### 可变数据类型:List,Set,Dict
19 | #### 不可变数据类型:Number,String,Tuple
20 |
21 | ## type与isinstance的区别
22 | * type()不认为子类是一种父类类型
23 | * isinstance()认为子类是一种父类类型
24 |
25 | ```python
26 | class A:
27 | pass
28 |
29 | class B(A):
30 | pass
31 |
32 | if __name__ == '__main__':
33 | a = A() # 父类
34 | b = B() # 子类
35 | print(type(a) is A) # True
36 | print(type(b) is A) # False, type()不认为子类是一种父类类型
37 | print(isinstance(a, A)) # True
38 | print(isinstance(b, A)) # True, isinstance()认为子类是一种父类类型
39 | ```
40 |
--------------------------------------------------------------------------------
/python_basic/Python读取大文本文件.md:
--------------------------------------------------------------------------------
1 | # Python读取大文本文件
2 | * read():一次读取文件的全部内容,可以指定size去读取
3 | * readline():每次读取一行
4 | * readlines():一次读取所有内容并按行返回list
5 |
6 | ## 按行读取
7 | ```python
8 | with open('test.txt', 'r', encoding='utf-8') as fr:
9 | for line in fr:
10 | print(line)
11 | ```
12 |
13 | ## 按块读取
14 | ```python
15 | def read_file_chunked(fr, block_size=1024):
16 | while True:
17 | chunk = fr.read(block_size)
18 | if not chunk:
19 | break
20 | yield chunk
21 |
22 |
23 | if __name__ == '__main__':
24 | with open('test.txt', 'r', encoding='utf-8') as fr:
25 | for chunk in read_file_chunked(fr):
26 | print(chunk)
27 | ```
28 |
29 | 或者
30 | ```python
31 | from functools import partial
32 | def read_file_chunked(fr, block_size=1024 * 8):
33 | # 首先使用 partial(fr.read, block_size) 构造一个新的无需参数的函数
34 | # 循环将不断返回 fr.read(block_size) 调用结果,直到其为 '' 时终止
35 | for chunk in iter(partial(fr.read, block_size), ''):
36 | yield chunk
37 | ```
38 |
--------------------------------------------------------------------------------
/python_basic/is.md:
--------------------------------------------------------------------------------
1 | ## ==与is的区别
2 | * ==:运算符比较两个对象的值(对象中保存的数据)
3 | * is:is 比较对象的id标识
4 |
5 | ```python
6 | a = [1,2,3]
7 | b = [1,2,3]
8 | print(a == b) # True
9 | print(a is b) # False
10 | ```
11 |
--------------------------------------------------------------------------------
/python_basic/json文件处理.md:
--------------------------------------------------------------------------------
1 | ## json文件处理
2 | #### json.dumps(): 把Python对象转换成字符串
3 | #### json.loads(): 把字符串转换成Python对象
4 |
5 | ```python
6 | import json
7 | #dumps() 把python对象转换成json字符串
8 | p_dict={'c':'aaa','b':'ss','a':'dd'}
9 |
10 | # 字典转换成json格式字符串
11 | # '{"a": "dd", "b": "ss", "c": "aaa"}'
12 | json.dumps(p_dict,sort_keys=True)
13 |
14 | # json格式字符串转换成字典
15 | obj = json.loads('{"a": "dd", "b": "ss", "c": "aaa"}')
16 | # dict
17 | print(type(obj))
18 |
19 | obj2 = json.loads('["aaa","bbb",222]')
20 | # list
21 | print(type(obj2))
22 |
23 | # 把Python对象写入到.json文件中
24 | l=['a','b','{"c":1,"d":2}']
25 | with open('dump.json','w') as f:
26 | json.dump(l,f)
27 | # 读取.json文件
28 | with open('dump.json','r') as f:
29 | # ['a', 'b', '{"c":1,"d":2}']
30 | print(json.load(f))
31 | ```
32 |
--------------------------------------------------------------------------------
/python_basic/main.md:
--------------------------------------------------------------------------------
1 | ## Python基础
2 | * [时间格式转换](时间格式转换.md)
3 | * [字节串与十六进制转换](字节串与十六进制转换.md)
4 | * [struct-序列化与反序列化](序列化与反序列化.md)
5 | * [文件路径处理](文件路径处理.md)
6 | * [创建临时文件](创建临时文件.md)
7 | * [文件目录扫描](文件目录扫描.md)
8 | * [XML文件处理](XML文件处理.md)
9 | * [utf8-BOM文件处理](utf8BOM文件处理.md)
10 | * [解析命令行参数(getopt)](解析命令行参数getopt.md)
11 | * [等分字符串](等分字符串.md)
12 | * [读取配置文件(configparser)](读取配置文件configparser.md)
13 | * [集合删除元素](集合删除元素.md)
14 | * [网络字节序(大端)与主机字节序(小端)转换](网络字节序与主机字节序转换.md)
15 | * [文件目录事件监控](文件目录事件监控.md)
16 | * [车牌格式校验](车牌格式校验.md)
17 | * [关于tuple](关于tuple.md)
18 | * [json文件处理](json文件处理.md)
19 | * [Excel文件处理](Excel文件处理.md)
20 | * [Python读取大文本文件](Python读取大文本文件.md)
21 | * [Python标准数据类型](Python标准数据类型.md)
22 | * [深拷贝与浅拷贝](深拷贝与浅拷贝.md)
23 | * [匿名函数,列表推导式,字典推导式,生成器表达式,map,filter,reduce](列表推导式.md)
24 | * [== 与 is的区别](is.md)
25 | * [python异常处理机制](python异常处理机制.md)
26 | * [\_\_new__()与\_\_init__()方法](new和init方法.md)
27 | * [@property 保护变量的访问与设置](保护变量的访问与设置.md)
28 | * [Python函数参数的传递机制](Python函数参数的传递机制.md)
29 | * [Python猴子补丁 monkey patch](猴子补丁.md)
30 | * [Python在内存中读写数据StringIO/BytesIO](Python在内存中读写数据.md)
31 |
--------------------------------------------------------------------------------
/python_basic/utf8BOM文件处理.md:
--------------------------------------------------------------------------------
1 | ## utf8-BOM文件处理
2 | #### 如果文件是utf8-BOM开头,会对文件转换造成影响,需要处理。
3 | ```python
4 | import codecs
5 | # b'\xef\xbb\xbf'
6 | codecs.BOM_UTF8
7 | with open(dev_filepath, 'r+b') as f:
8 | data = f.read()
9 | if data[:3] == codecs.BOM_UTF8:
10 | data = data[3:]
11 | # seek()方法用于移动文件读取指针到指定位置
12 | f.seek(0)
13 | # truncate() 方法用于截断文件,
14 | # 如果指定了可选参数size,则表示截断文件为size个字符。
15 | # 如果没有指定 size,则从当前位置起截断
16 | # 截断之后 size 后面的所有字符被删除
17 | f.truncate()
18 | f.write(data)
19 | ```
20 |
--------------------------------------------------------------------------------
/python_basic/保护变量的访问与设置.md:
--------------------------------------------------------------------------------
1 | # 保护变量的访问与设置
2 | 对于私有变量(双下划线)或者保护变量(单下划线),不允许外部直接访问,类似于Java的private,可以通过对外提供get,set接口来访问和修改这类变量,便于控制。
3 |
4 | * @property装饰器会将方法转换为相同名称的只读属性,相当于实现get方法
5 | * @xxx.setter装饰器使得可以直接通过 对象.xxx来修改保护变量的值,相当于实现set方法
6 |
7 | ```python
8 | class Student(object):
9 | def __init__(self, name):
10 | self.name = name
11 | self._score = None
12 |
13 | @property
14 | def score(self):
15 | return self._score
16 |
17 | @score.setter
18 | def score(self, value):
19 | self._score = value
20 |
21 | if __name__ == '__main__':
22 | s = Student('王大锤')
23 | s.score = 100 # 设置保护变量的值
24 | print(s.score) # 访问保护变量
25 | ```
26 |
--------------------------------------------------------------------------------
/python_basic/关于tuple.md:
--------------------------------------------------------------------------------
1 | **元组不可变指的是tuple数据结构中的物理内容不变,也就是元组保存的引用是不可变的。**
2 |
3 | **所以如果元组引用的元素是可变的,那即使元组本身包含的引用不可变,元素依然可变**
4 | ```python
5 | # 元组内保存的三个元素的内存地址是不可变的
6 | t1 = (1, 2, [30, 40])
7 | print(id(t1[-1])) # 1742619956424
8 | t1[-1].append(50)
9 | print(t1) # (1, 2, [30, 40, 50])
10 | print(id(t1[-1])) # 1742619956424
11 | ```
12 |
13 | 
14 |
15 | #### 尽量不要把可变对象放在元组中
16 | #### 增量赋值不是一个原子操作,虽然程序抛出异常,但还是会添加成功
17 | += 是赋值操作,相当于要改变引用地址,元组内引用地址是不可变的,所以会报错
18 | 答案:D
19 | 
20 |
--------------------------------------------------------------------------------
/python_basic/创建临时文件.md:
--------------------------------------------------------------------------------
1 | ## 创建临时文件
2 | ```python
3 | import tempfile
4 | import os
5 | tmpfd, tmp_file_path = tempfile.mkstemp()
6 | print(tmpfd) #文件描述符
7 | print(tmp_file_path) #临时文件的绝对路径
8 | os.close(tmpfd) #关闭文件
9 |
10 | # 防止占用资源
11 | # mktemp用于返回一个临时文件的路径,但并不创建该临时文件。
12 | tempfile.mktemp()
13 | ```
14 |
--------------------------------------------------------------------------------
/python_basic/字节串与十六进制转换.md:
--------------------------------------------------------------------------------
1 | ## “十六进制字符串”转“字节串”
2 | ```python
3 | data = '7c900030000001780000000030303035'
4 | bytes().fromhex(data)
5 | b'|\x90\x000\x00\x00\x01x\x00\x00\x00\x000005'
6 | ```
7 | ## “字节串”转“十六进制字符串”
8 | ### 方法一
9 | ```python
10 | def bytes_to_hex_str(bytes_data):
11 | if bytes_data:
12 | return ''.join(['%02x' % b for b in bytes_data])
13 | else:
14 | return ''
15 |
16 | data = b'\\\x00?\x00?\x00\\\x00E\x00:\x00'
17 | # 5c003f003f005c0045003a00
18 | print(bytes_to_hex_str(data))
19 | ```
20 | ### 方法二
21 | ```python
22 | import binascii
23 | data = b'\\\x00?\x00?\x00\\\x00E\x00:\x00'
24 | # 5c003f003f005c0045003a00
25 | print(binascii.hexlify(data).decode('utf-8'))
26 | ```
27 | ## “字节”转换成“十六进制”表示
28 | ```python
29 | # K是ascii中可见字符,所以编辑器在碰到0x4b的时候就把0x4b转换成了b'K'
30 | hex(ord(b'K')) # 0x4b
31 | ```
32 |
--------------------------------------------------------------------------------
/python_basic/序列化与反序列化.md:
--------------------------------------------------------------------------------
1 | ## 反序列化
2 | * unpack,字节转换成常用数据类型
3 | ```python
4 | data = '7c90000B00001818000000003235303630303035'
5 | import struct
6 | # (11,)
7 | struct.unpack('>H', bytes.fromhex(data)[2:4])
8 | ```
9 | ## 序列化
10 | * pack, 常用数据类型转换成字节串
11 | ```python
12 | s = struct.Struct('III')
13 | # b'\x0c\x00\x00\x00\x0f\x00\x00\x00\x10\x00\x00\x00'
14 | s.pack(12,15,16)
15 | ```
16 |
--------------------------------------------------------------------------------
/python_basic/总结.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daacheng/PythonBasic/2e13f23254e8685a11b62ddf6c13b3774d0a61ad/python_basic/总结.md
--------------------------------------------------------------------------------
/python_basic/文件目录扫描.md:
--------------------------------------------------------------------------------
1 | ## 文件目录扫描
2 | #### 扫描目录下所有文件,递归,但是文件数量多的情况下比较耗时:
3 | ```python
4 | all_files_list = []
5 | for root, dirs, files in os.walk(root_dir):
6 | for file in files:
7 | all_files_list.append(os.path.join(root, file))
8 | ```
9 | #### 高效率扫描,只针对单目录结构,不递归:
10 | ```python
11 | pkg_file_list = []
12 | all_file_generator = os.scandir(root_dir)
13 | for p in all_file_generator:
14 | pkg_file_list.append(p.path)
15 | ```
16 |
--------------------------------------------------------------------------------
/python_basic/文件路径处理.md:
--------------------------------------------------------------------------------
1 | ## 文件路径处理
2 | ```python
3 | import os
4 | path = r'C:\Users\daacheng\Desktop\bl_dev\imsiimei_whcs_bh_yyzkdw_dzwl_20180510103417_120.bcp'
5 | # 获取文件名称 imsiimei_whcs_bh_yyzkdw_dzwl_20180510103417_120.bcp
6 | print(os.path.basename(path))
7 | # 获取文件所在文件夹的路径 C:\Users\daacheng\Desktop\bl_dev
8 | print(os.path.dirname(path))
9 | # 返回元组,包含dirname和basename
10 | # ('C:\\Users\\daacheng\\Desktop\\bl_dev', 'imsiimei_whcs_bh_yyzkdw_dzwl_20180510103417_120.bcp')
11 | print(os.path.split(path))
12 | # 返回元组,包含文件路径名和文件扩展名
13 | # ('C:\\Users\\daacheng\\Desktop\\bl_dev\\imsiimei_whcs_bh_yyzkdw_dzwl_20180510103417_120', '.bcp')
14 | print(os.path.splitext(path))
15 | ```
16 |
--------------------------------------------------------------------------------
/python_basic/时间格式转换.md:
--------------------------------------------------------------------------------
1 | * Str-parse-time: “时间字符串”转换成“时间对象”
2 | * Str-format-time: “时间对象”转换成“时间字符串”
3 | ## time模块
4 |
5 | ```python
6 | import time
7 | time.time() # 1529653382.830719
8 |
9 | # time.struct_time(tm_year=2018, tm_mon=5, tm_mday=16, tm_hour=10, tm_min=21, tm_sec=2, tm_wday=2, tm_yday=136, tm_isdst=0)
10 | time.localtime()
11 |
12 | # 把时间(time.struct_time)转换成指定格式的字符串
13 | # '2018-06-22 15:49:59'
14 | time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
15 |
16 | # 把时间戳转换为指定格式字符串
17 | time.strftime('%Y%m%d%H%M%S', time.localtime(1529653382.830719))
18 | ```
19 | ## datetime模块
20 | ```python
21 | import datetime
22 |
23 | # 把 “指定格式的时间字符串” 转换为“datetime对象”
24 | dt_str = '2018-02-09 07:19:50'
25 | dt_obj = datetime.datetime.strptime(dt_str, "%Y-%m-%d %H:%M:%S")
26 | # datetime.datetime(2018, 2, 9, 7, 19, 50)
27 | dt_obj
28 |
29 | # 把“datetime对象” 转换为 “指定格式的时间字符串”
30 | # '20180209071950'
31 | dt_obj.strftime("%Y%m%d%H%M%S")
32 |
33 | # 把“指定格式的时间字符串” 转换为 “时间戳对象”
34 | dt_obj = datetime.datetime.strptime(s , "%Y-%m-%d %H:%M:%S")
35 | # 1518131990.0
36 | time.mktime(dt_obj.timetuple())
37 |
38 | # 把“指定格式的时间字符串” 转换为 “时间戳对象”
39 | # 1518131990.0
40 | time.mktime(time.strptime(s,'%Y-%m-%d %H:%M:%S'))
41 | ```
42 |
--------------------------------------------------------------------------------
/python_basic/猴子补丁.md:
--------------------------------------------------------------------------------
1 | # 猴子补丁
2 | **monkey patch允许在运行期间动态修改一个类或模块**
3 |
4 | * 在运行时替换方法、属性等
5 | * 在不修改第三方代码的情况下增加原来不支持的功能
6 | * 在运行时为内存中的对象增加patch而不是在磁盘的源代码中增加
7 |
8 | ```python
9 | class A:
10 | def func(self):
11 | print('这是A类下的func方法')
12 |
13 | # arg 这个参数是没有用到的,因为func有一个参数,如果这个函数没有参数的话不能这样直接赋值
14 | def monkey_func(arg):
15 | print('这是猴子补丁方法')
16 |
17 | if __name__ == '__main__':
18 | a = A()
19 | # 运行原类下的方法
20 | a.func() # 这是A类下的func方法
21 |
22 | # 在不改变原类代码的情况下,动态修改原类的方法,打补丁
23 | A.func = monkey_func
24 |
25 | # 运行替换后的方法
26 | a.func() # 这是猴子补丁方法
27 | ```
28 |
29 | ## 应用
30 | gevent通过打补丁的方式,利用自己的socket替换了python的标准socket模块,利用gevent协程处理高并发的情况
31 |
32 | ```python
33 | from gevent import monkey
34 | monkey.patch_all()
35 | import gevent
36 | from socket import *
37 |
38 |
39 | def talk(conn):
40 | while 1: # 循环通讯
41 | try:
42 | from_client_msg = conn.recv(1024)
43 | if not from_client_msg:break
44 | print("来自客户端的消息:%s" %(from_client_msg))
45 | conn.send(from_client_msg.upper())
46 | except:
47 | break
48 | conn.close()
49 |
50 |
51 | if __name__ == '__main__':
52 | server = socket()
53 | ip_port = ("127.0.0.1", 8001)
54 | server.bind(ip_port)
55 | server.listen(5)
56 | while 1: # 循环连接
57 | conn, addr = server.accept()
58 | gevent.spawn(talk, conn) # 开启一个协程
59 | server.close()
60 | ```
61 |
--------------------------------------------------------------------------------
/python_basic/等分字符串.md:
--------------------------------------------------------------------------------
1 | ## 等分字符串
2 | ```python
3 | import re
4 | '-'.join(re.findall(r'.{2}', 'F0B42998CE34')) # 'F0-B4-29-98-CE-34'
5 | ```
6 |
--------------------------------------------------------------------------------
/python_basic/网络字节序与主机字节序转换.md:
--------------------------------------------------------------------------------
1 | ## 网络字节序(大端)与主机字节序(小端)转换
2 | #### 字节序分为大端字节序和小端字节序:
3 | * 大端字节序是指一个整数的高位字节(32-31bit)存储在内存的低地址处,低位字节(0-7bit)存储在内存的高地址处
4 | * 小端字节序是指一个整数的高位字节(32-31bit)存储在内存的高地址处,低位字节(0-7bit)存储在内存的低地址处
5 | * 小端字节序又被称为主机字节序
6 | * 大端字节序也称为网络字节序
7 |
8 | ```python
9 | import socket
10 | import struct
11 | x = 1234
12 | # socket.ntohl() 把(32bit)正整数从网络序转换成主机字节序
13 | socket.ntohl(x) # 3523477504
14 |
15 | # socket.ntohs() 把(16bit)正整数从网络序转换成主机字节序
16 | socket.ntohs(x) # 53764
17 |
18 | # socket.htonl(x) 把(32bit)正整数从主机字节序转换成网络序
19 | socket.htonl(3523477504) # 1234
20 |
21 | # socket.htons(x) 把(16bit)正整数从主机字节序转换成网络序
22 | socket.htons(53764) # 1234
23 |
24 | # 字符串IPv4转换为 长度为4的字节串(32bit)
25 | socket.inet_aton('192.168.1.11') # b'\xc0\xa8\x01\x0b'
26 |
27 | # 长度为4的字节串(32bit)转换为 字符串IPv4
28 | socket.inet_ntoa(b'\xc0\xa8\x01\x0b') # '192.168.1.11'
29 |
30 | # 把标准字符串形式的IP 转换成 网络字节序(大端) 整型表示的IP
31 | struct.unpack(">I", socket.inet_aton('192.168.1.11'))[0] # 3232235787
32 |
33 | # 把网络字节序 整型表示的IP 转换成标准字符串形式的IP
34 | socket.inet_ntoa(struct.pack('I', socket.htonl(3232235787))) # '192.168.1.11'
35 | ```
36 |
--------------------------------------------------------------------------------
/python_basic/解析命令行参数getopt.md:
--------------------------------------------------------------------------------
1 | ## 解析命令行参数(getopt)
2 | ```python
3 | import getopt
4 | import sys
5 | print(sys.argv[1:]) # ['-h', '-t', 'bb', '-i', 'cc']
6 | opts, args = getopt.getopt(sys.argv[1:], 'i:o:e:c:f:t:h', ['check','output='])
7 | print(opts)
8 | print(args)
9 |
10 | # getopt中需要三个参数
11 | # 1、使用sys.argv[1:]过滤掉第一个参数(执行的脚本的名字,这个不需要)
12 | # 2、短格式分析串:'i:o:e:c:fh' 分别代表 -i -o -e -c -f 命令。后面有":"表示需要带参数。
13 | # 3、长格式分析串列表: ['check','output='] 表示 "help"命令 和 "output"命令,"="表示需要带参数。
14 | # 函数返回两个列表 opts, args
15 | # args为不属于格式信息的剩余的命令行参数,即不是按照getopt()里面定义的长或短选项字符和附加参数以外的信息。
16 | # 例如: 运行命令 python .\test.py -h -t bb -i cc
17 | # opts = [('-h', ''), ('-t', 'bb'), ('-i', 'cc')]
18 | # args = []
19 |
20 | ```
21 |
--------------------------------------------------------------------------------
/python_basic/读取配置文件configparser.md:
--------------------------------------------------------------------------------
1 | ## 读取配置文件(configparser)
2 | #### 配置文件格式:
3 | ```python
4 | [mysql]
5 | host = 172.16.2.207
6 | port = 3306
7 | db = WWW
8 | user = EEE
9 | passwd = 123445
10 |
11 | [csv]
12 | print_num = 100000
13 | ```
14 | #### 读取配置内容:
15 |
16 | ```python
17 | import configparser
18 |
19 | # 配置文件由节(sections)、键(key)、值(value)组成
20 | config = configparser.ConfigParser()
21 | config.read("all_export_conf", encoding='utf-8')
22 |
23 | # 获取配置文件所有的节sections ['mysql', 'csv']
24 | config.sections()
25 |
26 | # 获取某个节中的所有键 ['host', 'port', 'db', 'user', 'passwd']
27 | config.options('mysql')
28 |
29 | # 获取某个节中的某个键对应的value '172.16.2.207'
30 | config.get('mysql','host')
31 | config.get('mysql','port')
32 |
33 | # 添加一个配置文件节点
34 | config.add_section('test')
35 |
36 | # 给节点添加键值对
37 | config.set('test','name','daacheng')
38 | ```
39 |
--------------------------------------------------------------------------------
/python_basic/车牌格式校验.md:
--------------------------------------------------------------------------------
1 | ## 车牌格式校验
2 | ```python
3 | import re
4 | s1 = "浙AD12345*"
5 | s2 = "鄂A8P8F8D"
6 | s3 = ""
7 | s4 = "鄂A-8P8F8"
8 | regex = '^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][-]{0,1}[DF]?[A-Z0-9]{4}[A-Z0-9挂学警港澳领][DF]?$'
9 | print(re.match(regex,s1))
10 | print(re.match(regex,s2))
11 | print(re.match(regex,s3))
12 | print(re.match(regex,s4))
13 | ```
14 |
--------------------------------------------------------------------------------
/python_basic/集合删除元素.md:
--------------------------------------------------------------------------------
1 | ## 集合元素删除
2 | #### remove(),删除元素,元素不存在会报错
3 | ```python
4 | a=set('abcdefghijk')
5 | a.remove('a')
6 | a # {'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'}
7 | ```
8 |
9 | #### discard()删除元素,元素不存在不会报错
10 | ```python
11 | a=set('abcdefghijk')
12 | a.discard('m')
13 | a # {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'}
14 | ```
15 |
--------------------------------------------------------------------------------
/spiders/agent_pool/WebAPI_to_get_proxy.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, g
2 | import RedisClient
3 |
4 | """
5 | 对外提供web接口,通过提供的web接口,来获取redis中的代理
6 | g是上下文对象,处理请求时,用于临时存储的对象,每次请求都会重设这个变量。比如:我们可以获取一些临时请求的用户信息。
7 | """
8 |
9 |
10 | app = Flask(__name__)
11 |
12 |
13 | @app.route('/')
14 | def index():
15 | return '欢迎来到daacheng代理池系统
'
16 |
17 |
18 | def get():
19 | if not hasattr(g, 'redis'):
20 | g.redis = RedisClient.RedisClient()
21 | return g.redis
22 |
23 |
24 | @app.route('/random')
25 | def get_random_proxy():
26 | # 从代理池中返回一个代理
27 | redisdb = get()
28 | return redisdb.get_proxy()
29 |
30 |
31 | @app.route('/count')
32 | def count():
33 | # 查询代理池中代理的个数
34 | redisdb = get()
35 | return str(redisdb.get_proxy_count())
36 |
37 |
38 | @app.route('/all')
39 | def get_all():
40 | # 查询代理池中代理的个数
41 | redisdb = get()
42 | return str(redisdb.get_all_proxy())
43 |
44 |
45 | if __name__ == '__main__':
46 | app.run(host='0.0.0.0', port=5000)
47 | app.debug = True
48 |
--------------------------------------------------------------------------------
/spiders/dazhongdianping/decode_str.txt:
--------------------------------------------------------------------------------
1 | 廊江乐林陕澳风前扬业津城交福凤家昌治保乌上常花省路振齐农友湛源北温华充汉天银教坊锦邢健威肃宜临才年东合木徐苏古公关淮宾宁工明拥锡育波文鲁石沈湖桂吉都建太站市放胜康香广南绵莞贵武义徽茂成机环阳夏隆通黄滨泉潍济佛爱一区衡深信沿县岳台圳汕烟龙设结头门洛场中襄云安珠金军名学遵九厦利人无河封八湾庄谊晋街蒙博大四赣朝鞍主肥淄郑韶嘉兴皇旗创山富冈盐京祥镇远海疆定惠绍乡孝内永泰谐感迁生团昆黑曙开藏川肇西解光进哈向辽化衢新港沙幸体汾秦春宿清村尔迎民凰号府红园岛弄连甘和杭州重平道长梅青德浙心庆
--------------------------------------------------------------------------------
/spiders/dazhongdianping/test.py:
--------------------------------------------------------------------------------
1 |
2 | def main():
3 | with open('1.html', 'r', encoding='utf-8') as f:
4 | content = f.read()
5 | print(content)
6 |
7 |
8 | if __name__ == '__main__':
9 | main()
--------------------------------------------------------------------------------
/spiders/main.md:
--------------------------------------------------------------------------------
1 | ## Python爬虫
2 | * [Python爬虫之requests库](Python爬虫之requests库.md)
3 | * [Python爬虫之BeautifulSoup](Python爬虫之BeautifulSoup.md)
4 | * [Python爬虫之xpath解析](Python爬虫xpath解析.md)
5 | * [Python爬虫之selenium自动化](Python爬虫之selenium自动化.md)
6 | * [Python爬虫之构建自己的代理IP池](Python爬虫之构建自己的代理IP池.md)
7 | * [Python爬虫之知乎钓鱼贴图片爬取](Python爬虫之知乎钓鱼贴图片爬取.md)
8 | * [Python爬虫之uiautomator2常用操作](Python爬虫之uiautomator2常用操作.md)
9 | * [python爬虫之一尘论坛发帖数据爬取](python爬虫之一尘论坛发帖数据爬取.md)
10 | * [python爬虫之网易云音乐歌单歌曲列表及热门评论数据抓取](python爬虫之网易云音乐.md)
11 | * [一些概念](概念.md)
12 |
--------------------------------------------------------------------------------
/studynotes/Linux-vim编辑器.md:
--------------------------------------------------------------------------------
1 | # Linux-vim编辑器
2 | ## 一、vim三种工作模式
3 | #### 1.1、命令模式
4 | 在此模式下,可以使用上、下、左、右键或者 k、j、h、l 命令进行光标移动,还可以对文件内容进行复制、粘贴、替换、删除等操作。
5 | #### 1.2、输入模式
6 | 在输入模式下可以对文件执行写操作。
7 | #### 1.3、编辑模式
8 | 如果要保存、查找或者替换一些内容等,就需要进入编辑模式。
9 | ## 二、基本操作
10 | * 插入命令: i
11 | * 查找字符串命令: / ,查找多个匹配结果,可以n键向下查找,N向上查找。
12 | * x 删除光标所在的单个字符
13 | * dd 删除一整行(相当于剪切),p 粘贴
14 | * yy 复制单行
15 | * J 删除当前行的换行
16 | * u 撤销
17 | * w 保存不退出
18 | * q 不保存退出
19 | * ! 强制性操作
20 | * ZZ"命令退出,按两次"Shift+Z"快捷键方便,笔者强烈推荐。此时如果对文件没有修改,就是不保存退出;如果对文件已经进行了修改,就是保存后退出。
21 | * 命令行模式下 :set nu显示行数,:set nonu 不显示行数
22 | * 创建多个窗口,vim打开一个文件后,在命令行模式下执行 "sp 文件路径" 命令,再打开一个窗口,sp表示水平切分窗口,vs表示垂直切分窗口。
23 | * 切换窗口:ctrl + WW
24 |
--------------------------------------------------------------------------------
/studynotes/Linux文件权限.md:
--------------------------------------------------------------------------------
1 | # Linux文件权限
2 | ## 权限位
3 | 
4 | 
5 | 通过ls -l查看文件的详细信息,第一列就是权限位。
6 | * 第一位代表文件类型,"-":普通文件。
7 | * 第二~四位表示文件所有者权限,-r读权限,-w写权限,-x执行权限
8 | * 第五~七位表示文件所属组权限
9 | * 第八~十位表示文件其他人的权限
10 | ## chmod(修改权限)
11 | **chmod 命令的权限模式的格式是"[ugoa] [+-=] [rwx]"**
12 | * u表示所有者 user
13 | * g表示所属组 group
14 | * o表示其他的 others
15 |
16 | 例如:
17 | * chmod u+x 1_1.txt
18 | * chmod g+w,o+w 1_1.txt
19 | * chmod u=rwx 1_1.txt
20 |
21 | ### 通过数字赋予权限是最简单的
22 | * 4表示权限r
23 | * 2表示权限w
24 | * 1表示权限x
25 |
26 | **例如 chmod 755 1_1.txt 第一个数字"7":代表所有者的权限是"4+2+1",也就是读、写和执行权限。第二个数字"5":代表所属组的权限是"4+1",也就是读和执行权限。第三个数字"5":代表其他人的权限是"4+1",也就是读和执行权限。**
27 |
--------------------------------------------------------------------------------
/studynotes/Python之代码pythonic几种写法.md:
--------------------------------------------------------------------------------
1 | ## 两个变量值替换
2 |
3 | a,b= 5,6
4 | print(a) #5
5 | print(b) #6
6 | a,b=b,a
7 | print(a) #6
8 | print(b) #5
9 |
10 | ## 链式比较
11 |
12 | a=5
13 | b=4
14 | 24 else 0
50 | b #0
51 |
52 | ## Enumerate
53 |
54 | for i, e in enumerate(['a','b','c']):
55 | print(i,e) #0 a
56 | #1 b
57 | #2 c
58 |
59 | ## zip创建键值对
60 |
61 | #使用zip创建键值对
62 | key = ['a','b','c']
63 | val = [1,2,3]
64 | dict(zip(key,val)) # {'a': 1, 'b': 2, 'c': 3}
65 |
66 |
67 |
--------------------------------------------------------------------------------
/studynotes/Python之利用MongoDB存储图片.md:
--------------------------------------------------------------------------------
1 | # Python之利用MongoDB存储图片
2 | ## 存入图片到MongoDB数据库
3 |
4 | from pymongo import MongoClient
5 | from gridfs import *
6 | import os
7 | #连接mongodb
8 | client=MongoClient('localhost',27017)
9 | #取得对应的数据库
10 | db=client.pictures
11 | #取得对应的集合
12 | collection = db.test
13 | #图片路径
14 | img_path = r'C:\Users\daacheng\Desktop\timg.jpg'
15 |
16 | # 数据库其他字段信息
17 | img_info = {
18 | 'content_type': 'jpg',
19 | 'filename': 'timg.jpg',
20 | 'filepath': img_path
21 | }
22 |
23 | with open(img_path, 'rb') as f:
24 | #创建写入流
25 | fs = GridFS(db, collection="test")
26 | data = f.read()
27 | #将数据写入,文件类型和名称通过前面的分割得到
28 | img_id=fs.put(data, **img_info)
29 | print(img_id)
30 |
31 | ## 从MongoDB中下载图片
32 |
33 | from gridfs import *
34 | from pymongo import MongoClient
35 | from bson.objectid import ObjectId
36 | # 连接数据库
37 | client = MongoClient('localhost', 27017)
38 | db = client['pictures']
39 | fs = GridFS(db, collection='test')
40 | # 通过id查找图片
41 | image_id = '5c2c720381b1bc41ec02eb89'
42 | result = fs.find_one({'_id': ObjectId(image_id)})
43 | data = result.read()
44 | with open('a.jpg', 'wb') as f:
45 | f.write(data)
46 |
--------------------------------------------------------------------------------
/studynotes/Python利用socket实现简单http server.md:
--------------------------------------------------------------------------------
1 | # 利用socket实现http协议
2 |
3 | **http协议是基于tcp的,所以利用tcp可以实现http协议,实现一个简单的 http web server功能。**
4 |
5 | import socketserver
6 |
7 |
8 | body = """hello web client
"""
9 |
10 | response_param = ['HTTP/1.0 200 OK',
11 | 'Date: Mon, 13 May 2019 09:57:18 GMT',
12 | 'Content-Type: text/html; charset=utf-8',
13 | 'Content-Length: {}\r\n'.format(len(body.encode())),
14 | body]
15 | response = '\r\n'.join(response_param)
16 |
17 |
18 | class MyServer(socketserver.BaseRequestHandler):
19 | def handle(self):
20 | conn = self.request
21 | recv_data = b''
22 | while b'\n\n' not in recv_data and b'\n\r\n' not in recv_data:
23 |
24 | recv_data += conn.recv(1024)
25 | print(recv_data)
26 | conn.send(response.encode())
27 | conn.close()
28 |
29 |
30 | if __name__ == '__main__':
31 | # 第一步
32 | # 实例化server对象,传入本机ip,以及监听的端口号,还有新建的继承socketserver模块下的BaseRequestHandler类
33 | server = socketserver.ThreadingTCPServer(('127.0.0.1', 8000), MyServer)
34 | # 激活服务端
35 | server.serve_forever()
36 |
--------------------------------------------------------------------------------
/studynotes/Python基础习题.md:
--------------------------------------------------------------------------------
1 | ## 1、列表(list)和元组(tuple)的区别
2 | 相同:两者都可以包含任意类型的元素
3 | 不同:列表是可变的,元组是不可变的;可以通过namedtuple给元组的每个位置的元素命名;元组可以作为字典的key,列表不行。
4 | ## 2、set集合
5 | set集合是无序不重复的元素集合;集合成员可以做字典的键;支持用in或not in检查成员;len()得到集合大小;for循环迭代;因为集合无序,所以不支持索引和切片,
6 | 也没有keys来获取集合中元素的值。
7 | ## 3、浮点数比较相等的情况不能通过== 或者 !=,应该是一个范围
8 | x=0.6
9 | while x<1.0:
10 | print(x)
11 | x+=0.1
12 | #0.6
13 | #0.7
14 | #0.7999999999999999
15 | #0.8999999999999999
16 | #0.9999999999999999
17 |
18 | ## 4、sorted的根据key排序
19 | students=[('a',23),('b',46),('c',24),('d',12)]
20 | sorted(students,key = lambda x : x[1])
21 | ## 5、map,filte,reduce与匿名函数
22 | from functools import reduce
23 | list(map(lambda x : x+1,[2,3,4])) #[3,4,5]
24 | list(filter(lambda x : x>2,[2,3,4])) #[3, 4]
25 | reduce(lambda x,y:x+y,[2,3,4]) #9
26 | ## 6、双端队列 deque(double-ended queue)
27 | from collections import deque
28 | d = deque([],3)
29 | d.append(1)
30 | d.append(2)
31 | d.append(3)
32 | d.append(4)
33 | d #deque([2, 3, 4])
34 | d.appendleft(5)
35 | d #deque([5, 2, 3])
36 | ## 7、__new__和__init__区别
37 | __new__:是创建对象时调用,会返回当前对象的一个实例。
38 | __init__: 创建完对象后调用,对当前对象实例进行初始化操作,无返回值。
39 | 如果__new__返回一个对象的实例,会隐式调用__init__
40 |
--------------------------------------------------------------------------------
/studynotes/Python数据分析学习六--字符串操作.md:
--------------------------------------------------------------------------------
1 | # Python数据分析之字符串操作
2 | ## 字符串对象方法
3 |
4 | #字符串对象方法
5 | #split(),分割字符串,返回一个列表
6 | var = 'a,b ,c '.split(',') #['a', 'b ', 'c ']
7 | #strip()去除空白符 lstrip() rstrip()
8 | pieces = [x.strip() for x in var]
9 | pieces #['a', 'b', 'c']
10 |
11 | #join()列表转换成字符串
12 | ''.join(pieces) #'abc'
13 |
14 | #子串的定位find()、index()
15 | 'abc'.find(':') #find()方法,如果没有返回-1
16 | 'abc'.find('a') #find()方法如果有,返回索引
17 | 'abc'.index('b') #index()方法如果有返回索引,没有抛异常
18 |
19 | #count()记录子串出现的次数
20 | 'aaabc'.count('a') #3
21 |
22 | #replace()替换
23 | 'abcaddd'.replace('d','') #'abca'
24 | ## 正则表达式re
25 |
26 | import re
27 | #正则表达式模块findall()、match()、search()、split()、sub()、subn()
28 | text = 'a b c'
29 | re.split('\s+',text) #['a', 'b', 'c']
30 |
31 | regex = re.compile('\s+')
32 | regex.split(text) #['a', 'b', 'c']
33 |
34 | p=re.compile('a')
35 | p.findall('bcasa') #['a', 'a']
36 |
37 | p.search('cda').span() #(2, 3)
38 |
39 | print(p.match('cda')) #None
40 |
41 | p.sub('1','cda') #'cd1'
42 |
--------------------------------------------------------------------------------
/studynotes/Python爬虫--设置代理.md:
--------------------------------------------------------------------------------
1 | # Python爬虫--设置代理
2 | ## 一、requests设置代理,通过proxies参数
3 | requests通过构造字典,通过参数**proxies**即可。
4 |
5 | import requests
6 | def main():
7 | proxies = {
8 | 'http': 'http://123.157.67.30:34942'
9 | }
10 | res = requests.get('http://httpbin.org/get', proxies=proxies)
11 | print(res.text)
12 | if __name__ == '__main__':
13 | main()
14 |
15 | ## 二、selenium设置代理
16 | selenium在创建Chrome对象的时候,需要传入参数chrome_options.
17 | * 先创建ChromeOptions对象 chrome_options = webdriver.ChromeOptions()
18 | * 传入代理服务器参数 chrome_options.add_argument('--proxy-server=http://123.157.67.30:34942')
19 | * 创建浏览器对象时,将ChromeOptions作为参数传入。
20 |
21 | import time
22 | from selenium import webdriver
23 | def main():
24 | chrome_options = webdriver.ChromeOptions()
25 | chrome_options.add_argument('--proxy-server=http://123.157.67.30:34942')
26 | browser = webdriver.Chrome(chrome_options=chrome_options)
27 | browser.get('http://httpbin.org/get')
28 | time.sleep(9)
29 | browser.close()
30 | if __name__ == '__main__':
31 | main()
32 |
--------------------------------------------------------------------------------
/studynotes/《深入浅出统计学》笔记下.md:
--------------------------------------------------------------------------------
1 | ## 第十章:抽取样本
2 | 样本:从总体中选取的相对较小的集合,可用于做出关于总体本身的结论。
3 | 简单随机抽样:随机选择抽样单位并形成样本,包括重复抽样和不重复抽样。(具体方式包括抽签或使用随机编号生成器)
4 | 分层抽样:将总体划分为几个组或几个层,每一层尽可能与其他层不一样(比如糖果按颜色分层),分层好之后,对每一层执行简单随机抽样。
5 | 整群抽样:将总体划分为几个群,其中每个群尽量与其他群相似,随后通过简单随机抽样选取群,再接着对群中的对象进行抽样。
6 | 系统抽样:选取一个数字K,然后每到第K个抽样单位就抽样一次。
7 | ## 第十一章:总体和样本的估计
8 | ### 通过样本估计总体
9 | 统计量太大时,我们无法通过总体计算出总体的均值μ,或方差σ²时,而只能通过样本数据估计这些参数。**一个总体参数的点估计量(由样本数据得出,是对总体参数的估计)就是可用于估计总体参数数值的某个函数
10 | 或者算式,比如我们能用样本均值û 估计总体均值μ,因此样本均值就是总体均值的点估计量**
11 |
12 | 
13 |
14 | ### 通过总体估计样本(样本比例,样本均值)
15 | 比例的抽样分布:从同一个总体(X~B(n,p))中取得的所有大小为n的可能样本,由这些样本的比例形成的分布,就是“比例的抽样分布”,用Ps代表样本比例随机变量。
16 |
17 | **E(Ps)=p, Var(Ps)=pq/n 如果n>30,则Ps符合正态分布:Ps~N(p,pq/n),连续性修正时+1/2n 或 -1/2n**
18 |
19 | 均值的抽样分布:利用从所有可能样本得出的所有样本均值形成一个分布,叫做“均值的抽样分布”。
20 |
21 | 
22 |
23 | 中心极限定理:如果从一个非正态总体X中取出一个样本,且样本很大,则样本均值的分布近似为正态分布。如果总体的均值为μ,方差为σ²,且样本数很大,则样本均值的分布X'~N(μ,σ²/n)
24 |
25 | **中心极限定理应用二项分布**X~B(n,p),则X'~N(np,pq)
26 |
27 | **中心极限定理应用泊松分布**X~Po(λ),则X'~N(λ,λ/n)
28 | ## 第十二章:置信区间
29 | 求置信区间步骤:
30 | 1、首先选择用于构建置信区间的总体统计量。(比如均值)
31 | 2、求出统计量的抽样分布。
32 | 3、确定你所需要的置信水平(比如95%)。
33 | 4、求出置信区间的上下限(a,b)
34 |
--------------------------------------------------------------------------------
/studynotes/二、数据链路.md:
--------------------------------------------------------------------------------
1 | # 数据链路
2 | ## 一、数据链路层的作用
3 | **数据链路层的协议定义了通过通信媒介(电缆,光纤,电波,红外线等)互联的设备之间传输的规范。**
4 |
5 | **把物理层和数据链路层放在一起来看。计算机是用二进制0和1来表示信息,而实际的通信媒介(电缆,光纤,电波,红外线等)之间处理的是电压的高低,光的闪灭,以及电波的强弱等信号。
6 | 物理层的作用是把这些信号与二进制的0和1进行转换。数据链路层处理的也不说单纯的0和1序列,数据链路层把01集合成一个叫做帧的数据块,然后再进行传输**
7 | ## 二、数据链路相关技术
8 | ### 2.1、关于MAC地址
9 | **MAC地址是用于识别数据链路中互相连接的每一个节点的**。MAC地址长48bit,第3-24位表示厂商识别码,每个NIC厂商都有特定唯一的识别数字,25-48位是厂商内部为识别每一个网卡而用。
10 | 以此保证了世界上不会有相同MAC地址的网卡。MAC常用十六进制表示,如:30-9C-23-1D-25-71
11 | ### 2.2、共享介质型网络
12 | **根据通信介质的使用方式,可以将网络分成共享介质型和非共享介质型**。
13 | **共享介质型网络指多个设备共享同一个通信介质(线路),因此有必要对通信介质进行访问控制,介质访问控制方式有两种:争用方式和令牌传递方式。**
14 | * 争用方式:数据链路上的每个节点(主机)争夺获取数据传输的权利,采用先到先得的方式占用线路发送数据。如果同时发送帧,会出现冲突。
15 | * 令牌传递方式:沿着令牌环发送一种叫做‘令牌’的特殊报文,只有获得令牌的站点(主机)才有权利发送数据。不会发生冲突。
16 | ### 2.3、非共享介质型网络
17 | **非共享介质型网络是对介质采取专用的一种传输控制方式。这也是以太网的主流方式,通过以太网交换机构建网络,交换机与计算机之间通过端口一对一相连接,从而实现高效的通信。**
18 | ### 2.4、根据MAC地址转发
19 | 根据MAC地址进行转发的设备也就是之前说的二层交换机(网桥),跟据MAC地址转发原理如图:
20 | 
21 | ## 三、以太网
22 | 初期的以太网是多台终端使用同一根电缆的共享介质型网络,现在一般都是用终端与交换机之间独占电缆的方式进行通信(一台电脑一根网线连接交换机)。
23 |
--------------------------------------------------------------------------------