![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
铁蛋嘟嘟噜
明日も頑張ろぜ
展开
-
剑指offer-面试题43:n个骰子的点数
扔n个骰子,求所有点数之和出现的概率 思路1:递归思想,扔一颗骰子,然后跟n-1个骰子的结果做计算 思路2:动态规划思想,递推,用一个数组保存n-1个骰子的概率结果。 class Solution1: """ 递归方法 """ def getDicePointProbRecursively(self, n): if n == 0: return ...原创 2019-11-20 17:58:21 · 264 阅读 · 0 评论 -
剑指offer-逆序对-归并排序-非递归-python
def InversePairs(data): # write code here count = 0 length = len(data) grp_cnt = length grp_len = 1 result = data.copy() while grp_cnt >= 1: cur = 0 whil...原创 2019-04-26 21:48:33 · 354 阅读 · 0 评论 -
剑指offer-二叉树层次遍历求树深度-python
# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def TreeDepth(self, pRoot): ...原创 2019-04-27 13:08:56 · 392 阅读 · 0 评论 -
快速排序-python-递归
def quick_sort(arr): if len(arr) <= 1: return arr mid = arr[0] left = [] equal = [] right = [] while arr: element = arr[0] if element > mid: ...原创 2019-04-28 21:35:22 · 94 阅读 · 0 评论 -
剑指offer-数组中只出现一次的数字-hashmap-异或-python
hashmap做法 def FindNumsAppearOnce(array): # write code here candicate = set() for element in array: if element in candicate: candicate.remove(element) else: ...原创 2019-04-29 11:39:23 · 331 阅读 · 0 评论 -
剑指offer-和为S的连续正数序列-python
找规律版 # -*- coding:utf-8 -*- from math import sqrt, ceil class Solution: def FindContinuousSequence(self, tsum): # write code here if tsum<=2: return [] maxn ...原创 2019-04-29 17:44:55 · 299 阅读 · 0 评论 -
剑指offer-表示数值的字符串-python
题目描述 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100",“5e2”,"-123",“3.1416"和”-1E-16"都表示数值。 但是"12e",“1a3.14”,“1.2.3”,"±5"和"12e+4.3"都不是。 # -*- coding:utf-8 -*- class Solution: # s字符串 def isNumeric(sel...原创 2019-05-01 13:52:34 · 345 阅读 · 0 评论 -
剑指offer-删除链表中重复的节点-python
使用了三个指针 # -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteDuplication(self, pHead): # write ...原创 2019-05-01 15:22:43 · 167 阅读 · 0 评论