![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
franklin_yuan
学而时习之,不亦悦乎
展开
-
python 丢沙包代码实现
#coding=utf-8"""n是玩的人数,从第一个人开始数数,输到3出局"""n = int(raw_input("input num:"))arr = [ i for i in range(1,n+1)]k = 1 # 记录数数m = 0 # 从第一个人开始数while len(arr) > 1: if k % 3 == 0: del arr...原创 2018-06-12 23:19:10 · 303 阅读 · 0 评论 -
python之从尾到头打印单链表
# coding=utf-8class SingleNode: def __init__(self, item): self.item = item self.next = Noneclass SingleLinkedList: """ is_empty() 链表是否为空 print_end_to_head() 从尾到...原创 2018-11-04 23:25:08 · 906 阅读 · 0 评论 -
python之空格替换
实现方式一:实现方式二:原创 2018-11-04 23:00:42 · 8436 阅读 · 0 评论 -
python之二维数组中的查找
# 实现方式一def find_num(matrix, num): """二维数组中的查找""" tmp = [i for j in matrix for i in j if i == num] return tmp is not None# 实现方式二def find_num2(matrix, num): """二维数组中的查找"""原创 2018-11-04 22:53:57 · 6269 阅读 · 0 评论 -
python数组去重
# coding:utf-8# 数组去重alist = [1, 3, 5, 2, 3, 5]# 方式一# alist = list(set(alist))# print(alist)# 方式二def duplicate_list(alist): tmp = [] for i in alist: if i not in tmp: ...原创 2018-10-19 23:07:15 · 3066 阅读 · 0 评论 -
python之斐波那契数列
# coding:utf-8def fib(n): tmp = [1, 1] if n < 2: print('arg n > 2') return 1 for i in range(2, n): tmp.append(tmp[i-1] + tmp[i-2]) return tmpif __n...原创 2018-10-15 22:15:18 · 361 阅读 · 0 评论 -
python之求1+2+3+...+n
# coding: utf-8class Solution: def sum(self, n): """求1 + 2 + 3 +...+ n""" return sum(range(1, n+1))if __name__ == '__main__': obj = Solution() s = obj.sum(100) p...原创 2018-10-13 18:35:48 · 12441 阅读 · 0 评论 -
python之数组中重复的数字
# coding: utf-8class Solution: def duplicate(self,alist): """返回数组中重复的数字""" tmp = [] for item in alist: if alist.count(item) > 1: tmp.app...原创 2018-10-13 18:29:16 · 2501 阅读 · 1 评论 -
python扁平化输出字典
in_data = { "frank": { "Math": {"teacher": "zhang", "score": "75"}, "English": {"teacher": "xu", "score": "65"}, &quo原创 2018-10-06 20:28:07 · 1140 阅读 · 0 评论 -
python 实现快速排序
# coding : utf-8def quick_sort(arr): if len(arr) <= 1: return arr tmp = quick_sort([lt for lt in arr[1:] if lt < arr[0]]) + [arr[0]] + quick_sort([ge for ge in arr[1:] if ge &...原创 2018-06-20 19:13:49 · 186 阅读 · 0 评论 -
python 选择排序算法实现
#coding=utf-8def select_sort(arr): tmp = [] while len(arr) > 0: t = min(arr) arr.remove(t) # tmp.insert(0,t) tmp.append(t) ...原创 2018-06-12 23:20:36 · 163 阅读 · 0 评论 -
python二叉树实现
class Node(object): """元素节点""" def __init__(self, elem=None, lchild=None, rchild=None): self.elem = elem self.lchild = lchild self.rchild = rchildclass Tree(object)...原创 2018-11-12 23:53:36 · 769 阅读 · 0 评论