代码编织梦想

正则表达式-爱代码爱编程

https://www.jianshu.com/p/9fd05dfdde48 背景 我经常使用sublime去处理很多文件, 利用强大的正则表达式, 将一些日志以及excel文本进行格式化为特定内容. 最近经常遇到只保留我需要的行, 其他行删除掉. 也就需要用到正则中的不等于, 找了好几次, 觉得还是有必要记下来留用, 不用每次都去google了, 毕

GIT的简单使用-爱代码爱编程

一、给远程仓库配置SSH 不建议使用github,网络太慢,现在github有的功能码云都有。使用SSH克隆代码,不要再使用http了,这样可以避免每次push代码的时候都要输密码。链接:SSH是什么?如何获取SSH?二、克隆远程仓库到本地 使用命令:git clone 远程仓库项目的SSH地址使用sourceTree(4.0.2): 三、GIT是如

pta 7-10 ZZU联盟 (25分) 简单题-爱代码爱编程

2018年11月3日,万众瞩目的英雄联盟S8世界赛总决赛在韩国仁川开打,8年来第一次同组两支战队在总决赛争夺冠军,IG和FNC的对决引玩家期待。最终S8世界赛冠军诞生!IG3:0击溃FNC拿下胜利!中国LOL拿下世界冠军! ig.jpg ACM-ICPC实验室(对编程、算法感兴趣的小伙伴欢迎加QQ群号:562888278)的成员得知消息后激动不已,决定

python--Hot 100--简单--1. 两数之和-爱代码爱编程

from typing import List class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: hashtable = dict() for i in range(len(nums)):

python--hot 100--简单--1--34. 在排序数组中查找元素的第一个和最后一个位置-爱代码爱编程

方法:核心思想是使用二分查找 代码: from typing import List class Solution: def searchRange(self, nums: List[int], target: int) -> List[int]: l, r, mid = 0, len(nums) - 1, 0

python--剑指offer--简单--68 - II. 二叉树的最近公共祖先-爱代码爱编程

class Solution: def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNode) -> TreeNode: if not root or root == p or root == q: return root l

python--剑指offer--简单--68 - I. 二叉搜索树的最近公共祖先-爱代码爱编程

class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def lowestCommonAncestor(self, root: 'Tr

python--剑指offer--简单--65. 不用加减乘除做加法-爱代码爱编程

class Solution: def add(self, a: int, b: int) -> int: x = 0xffffffff a, b = a & x, b & x # python中将python存储补码的形式转换为32位有符号数的补码形式,用另一个数字表示出来

【必读】10分钟带你实现线程池C++版-爱代码爱编程

文章目录 简单线程池C++实现1 什么是线程池2 线程池分类3 线程池工作流程4 C++实现4.1 ring_buffer.cpp ring_buffer.h4.2 thread_pool.h thread_pool.cpp5 代码解析6 参考资料 简单线程池C++实现 最近在看如何实现自动求导,然后遇到了线程池,使用线程池对矩阵运算进行加速

python--剑指offer--简单--61. 扑克牌中的顺子-爱代码爱编程

from typing import List class Solution: def isStraight(self, nums: List[int]) -> bool: ma, mi = 0, 14 repeat = set() for num in nums:

python--剑指offer--简单--59 - I. 滑动窗口的最大值-爱代码爱编程

from typing import List class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: deque = collections.deque() res, n = [], len(nu

python--剑指offer--简单--58 - II. 左旋转字符串-爱代码爱编程

代码 class Solution: def reverseLeftWords(self, s: str, n: int) -> str: return s[n:] + s[:n] 代码 class Solution: def reverseLeftWords(self, s: str, n: int)

python--剑指offer--简单--58 - I. 翻转单词顺序-爱代码爱编程

代码 class Solution: def reverseWords(self, s: str) -> str: i = j = len(s) - 1 res = [] while i >= 0: while i >= 0 and s[i] != ' '

python--剑指offer--简单--57 - II. 和为s的连续正数序列-爱代码爱编程

// java代码 class Solution { public int[][] findContinuousSequence(int target) { List<int[]> vec = new ArrayList<int[]>(); int sum = 0, limit = (

python--剑指offer--简单--57. 和为s的两个数字-爱代码爱编程

from typing import List class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: length = len(nums) if length == 1: retu

python--剑指offer--55 - II. 平衡二叉树-爱代码爱编程

后序遍历 + 剪枝 (从底至顶) 此方法为本题的最优解法,但剪枝的方法不易第一时间想到。 思路是对二叉树做后序遍历,从底至顶返回子树深度,若判定某子树不是平衡树则 “剪枝” ,直接向上返回。 复杂度分析: 时间复杂度 O(N)O(N): NN 为树的节点数;最差情况下,需要递归遍历树的所有节点。 空间复杂度 O(N)O(N): 最差情况下(树退化为链

python--剑指offer--55 - I. 二叉树的深度-爱代码爱编程

方法一:后序遍历(DFS) 复杂度分析: 时间复杂度 O(N): N 为树的节点数量,计算树的深度需要遍历所有节点。空间复杂度 O(N): 最差情况下(当树退化为链表时),递归深度可达到 N 。class TreeNode: def __init__(self, x): self.val = x self.le

python--剑指offer--简单--54. 二叉搜索树的第k大节点-爱代码爱编程

代码 class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def kthLargest(self, root: TreeNode, k

python--剑指offer--53 - II. 0~n-1中缺失的数字-爱代码爱编程

from typing import List class Solution: def missingNumber(self, nums: List[int]) -> int: # 注意题目要求数组长度为n-1,则该数组的取值范围为[0, n-1]共n个数,数组中保存这n个数的(n-1)个数,需找出未保存的那个数

python--剑指offer--简单--53 - I. 在排序数组中查找数字 I-爱代码爱编程

from typing import List class Solution: def search(self, nums: List[int], target: int) -> int: if not nums: return 0 l, r = 0, len(nums)-1