算法总结
文章平均质量分 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 · 98 阅读 · 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 · 891 阅读 · 0 评论 -
python中sorted和sort的key
目录1、调用方式:2、返回值:3、操作对象是否变化:什么对象可以排序sort:sorted:排序的key有趣的排序题:1、调用方式: sort是方法(需要对象来调用) sorted是函数(入参是对象)2、返回值: sort无返回值 sorted返回排序好的对象,不设置key参数...原创 2021-03-11 15:51:55 · 7327 阅读 · 0 评论 -
摩尔投票python
leetcode上题连接:https://leetcode-cn.com/problems/majority-element/solution/解题思路:投票的原理1、遍历一遍2、认为i位置为票数最多的,初始值times=13、下一个位置一样那就times+1,反之-14、如果times=0的时候,那我们就考虑这个人不是我们要选举的首领了,换为这个位置的值# python3才有的类型限制from typing import Listdef moer(num_lis.原创 2021-01-20 00:20:49 · 200 阅读 · 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 · 140 阅读 · 0 评论