python 基础
紫砂痕
这个作者很懒,什么都没留下…
展开
-
leetcode 排序+动态规划的妙用
今天来学习一下区间中的任务序列问题。、1.1. leetcode1626 无矛盾的最佳球队1.1 普通dfs搜索超时:class Solution: def isNormal(self,scores, ages, s): flag=True for i in range(len(s)-1): if ages[s[i]]<ages[s[-1]] and scores[s[i]]>scores[s[-1]]:原创 2021-04-18 18:16:12 · 228 阅读 · 1 评论 -
leetcode BFS
1. leetcode 网络延迟时间有解时,就是求最短距离的问题,到所有叶子节点的最短距离的最大值。import collectionsclass Solution: def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: dicta = collections.defaultdict(list) for t in times: dict原创 2021-04-06 23:49:18 · 117 阅读 · 0 评论 -
leetcode堆
1. leetcode 1054 距离相等的条形码```pythonimport collectionsclass Solution: def rearrangeBarcodes(self, barcodes: List[int]) -> List[int]: if len(barcodes) == 1: return barcodes res = [] dicta = collections.defaultdi原创 2021-04-05 00:25:27 · 73 阅读 · 0 评论 -
leetcode二叉树
二叉树的一些事情1.二叉树的特点1.1 题1. leetcode235 二叉搜索树的最近公共祖先。1.1.11.1.2 结合二叉搜索树的特性1.1.3 递归解法1.二叉树的特点1.1 题1. leetcode235 二叉搜索树的最近公共祖先。1.1.1搜索到对应的p和q 所在位置,并记录先前的父节点找到的最后一个共有的节点,也就是最近公共点# Definition for a binary tree node.# class TreeNode:# def __init__(s原创 2021-04-04 18:23:54 · 330 阅读 · 1 评论 -
leetcode 1722
0. 题目1. 并查集+ 哈希表import collectionsclass Solution: def minimumHammingDistance(self, source: List[int], target: List[int], allowedSwaps: List[List[int]]) -> int: n = len(source)+1 f = [i for i in range(n)] def getfather(x)原创 2021-02-01 23:02:15 · 116 阅读 · 0 评论 -
leetcode-1726同积元组
1. 题目留意:一组数据可以组成8个满足条件的元组结合排序!!! 很关键2. 解决方法:1. 排序 + dfs得到数据的排列组合class Solution: def isSatisitfy(self, num): if num[0]*num[3] == num[2]*num[1]: return True else: return False def tupleSa原创 2021-01-23 00:07:05 · 212 阅读 · 1 评论 -
leetcode --贪心算法
1. 贪心算法问题可分解为多个子问题;问题的最优解,可由每个子问题的最优解构成2. 5634.删除子字符串的最大得分解法一:class Solution: def maximumGain(self, s: str, x: int, y: int) -> int: res = 0 if y>x: s1 = "ba" v1 = y s2 = "ab"原创 2021-01-10 18:47:47 · 147 阅读 · 0 评论 -
leetcode --位运算基础知识以及应用
1. 位运算基础1.1 基本表达a与b: a&ba或b: a|ba异或b: a^b1.2 进制转换2. 题目2.1 5649. 解码异或后的数组这个题目考查异或相关的知识a^b=c 能推出c^b =aclass Solution: def decode(self, encoded: List[int], first: int) -> List[int]: res = [first] for i in range(len(enco原创 2021-01-10 17:46:54 · 211 阅读 · 0 评论 -
python 刷题必备基础
1. 获取int最大值sys.maxint原创 2020-08-20 21:49:32 · 369 阅读 · 0 评论 -
Kaggle:Elo顾客忠诚度预测问题
Kaggle:Elo顾客忠诚度预测问题1. 问题分析2. 数据预处理3. 特征工程构建4. 训练模型参考链接:Elo顾客忠诚度 —— kaggle数据1. 问题分析这个数据集来自Kaggle这是链接,是Elo(巴西最大的本土支付品牌之一)和Kaggle合作的项目,通过Elo的匿名数据集预测每个客户的忠诚度(具体到card_id),以及查找影响客户忠诚度的因素。这个是数据集是虚构的(官方是这么...原创 2019-03-07 23:22:32 · 1715 阅读 · 0 评论 -
Python 基础-- collections. Counter
Python 基础-- collections. CounterPython 基础-- collections. CounterCounter 作用Example1、输入是一个字符串,统计各字符的出现的次数2、输入是一个dict,统计各字符的出现的次数3、element()参考链接Python 基础-- collections. Counterfrom collections import C...原创 2019-03-03 18:13:00 · 269 阅读 · 0 评论