算法总结
文章平均质量分 65
chenchen_nini
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
贪心-python
1、3. 无重复字符的最长子串 def lengthOfLongestSubstring(self, s: str) -> int: n, max_n, temp = 0, 0, "" for i in s: if i not in temp: temp += i n += 1 else: if n > ma原创 2021-10-26 13:33:27 · 153 阅读 · 0 评论 -
回溯算法-python
1、131. 分割回文串 给你一个字符串s,请你将s分割成一些子串,使每个子串都是回文串。返回s所有可能的分割方案。 回文串是正着读和反着读都一样的字符串 #错误写法 def partition(s): def huiwen(temp): """判断是否是回文串""" return temp == temp[::-1] def backtracking(s_temp, result, temp_result): i...原创 2021-10-20 14:31:47 · 1065 阅读 · 0 评论 -
python中sorted和sort的key
目录 1、调用方式: 2、返回值: 3、操作对象是否变化: 什么对象可以排序 sort: sorted: 排序的key 有趣的排序题: 1、调用方式: sort是方法(需要对象来调用) sorted是函数(入参是对象) 2、返回值: sort无返回值 sorted返回排序好的对象,不设置key参数...原创 2021-03-11 15:51:55 · 8600 阅读 · 0 评论 -
摩尔投票python
leetcode上题连接:https://leetcode-cn.com/problems/majority-element/solution/ 解题思路:投票的原理 1、遍历一遍 2、认为i位置为票数最多的,初始值times=1 3、下一个位置一样那就times+1,反之-1 4、如果times=0的时候,那我们就考虑这个人不是我们要选举的首领了,换为这个位置的值 # python3才有的类型限制 from typing import List def moer(num_lis.原创 2021-01-20 00:20:49 · 311 阅读 · 0 评论 -
排序总结-python
排序学习python 二叉搜素 选择排序selectSort 冒泡排序bubbleSort 基础版:(复杂度固定用for) 改良版:(标志是否交换,有最好情况) 插入排序insertSort 快速排序quickSort 归并排序mergeSort 排序学习python 二叉搜素 def binarySearch(target,sortedList): """二分查找有序数组中目标值""" left = 0 right = len(sortedList.原创 2021-01-14 20:01:57 · 299 阅读 · 0 评论
分享