
算法与数据结构
文章平均质量分 60
Luban250
这个作者很懒,什么都没留下…
展开
-
Python解LeetCode 771: Jewels and Stones
给定A字符串,寻找B字符串中有多少字符出现在A中,重复出现的计算次数,拟采用位操作,为两个字符串计算位表示,然后让这两个位表示求与操作,将结果的二进制表示中各个位相加,或者说计算其中有几个数字1。关于字符串的位操作参见Python解LeetCode 318: Maximum Product of Word Lengths,解答代码如下:import stringclass Solution(object): def numJewelsInStones(self, J, S): """ :t原创 2020-09-02 21:23:17 · 218 阅读 · 0 评论 -
Python解LeetCode 318: Maximum Product of Word Lengths
提供两种解法,第一种利用Python内置的set类型判断两个单词是否有重叠字符,复杂度高,无法通过全部测试;第二种方法使用位运算判断两个单词是否存在重叠字符,复杂度有所降低,可通过全部测试,但是运行时间排名也比较靠后。下述两种答案仅供参考交流,仍有很大的改进空间。第一种解法:from itertools import permutationsclass Solution(object): def maxProduct(self, words): """ :type words: List[st原创 2020-09-01 22:21:35 · 258 阅读 · 0 评论 -
Python冒泡排序
# -*- coding: utf-8 -*-"""Bubble SortAuthor : Date : 2016-07-04Version: 1.0"""def bubbleSort(olist): length = len(olist) for i in range(length-1): for j in range(length-1)原创 2016-07-05 08:58:41 · 425 阅读 · 0 评论 -
选择排序python版
# -*- coding: utf-8 -*-"""selection SortAuthor : Date : 2016-07-06Version: 1.0"""def selectionSort(olist): length = len(olist) for i in range(length-1): minPosition = i原创 2016-07-06 21:58:53 · 392 阅读 · 0 评论 -
快速排序算法的Python实现
快算排序算法,快速排序算法的python实现,Python实现款速排序算法原创 2018-01-17 14:41:07 · 1274 阅读 · 0 评论