自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(15)
  • 收藏
  • 关注

原创 排序算法:堆排序

堆排序def parent(i): return i//2def left(i): return 2*i+1def right(i): return 2*i+2def max_heapify(A,i): l=left(i) r=right(i) largest=i if l<length: if A[l]>A[i]: largest=l if r<length:

2021-08-20 12:53:01 109

原创 二叉树建立及其前序、中序、后序和层序遍历

二叉树建立及其前序、中序、后序和层序遍历class Treenode(): def __init__(self, value, left=None, right=None) -> None: self.val=value self.left=left self.right=rightclass Tree(): def __init__(self, root=None) -> None: self.root=ro

2021-08-17 12:39:52 160

原创 排序:快速排序

快速排序def parition(l): length=len(l) if length==1: return l med=length-1 i=0 while i < med: if l[i]>=l[med]: tmp=l[med] l[med]=l[i] l[i]=l[med-1] l[med-1]=tmp

2021-08-13 16:15:57 104

原创 排序:归并排序

欢迎使用Markdown编辑器你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。新的改变我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:全新的界面设计 ,将会带来全新的写作体验;在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式 进行展示;增加了 图片

2021-08-13 16:13:52 83

原创 螺旋矩阵

螺旋矩阵给定一个m行n列的矩阵,按顺时针螺旋顺序返回矩阵中的所有元素。例如:1逐层返回,外层到内层。每层分四个方向。class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: if not matrix or not matrix[0]: return list() row = len(matrix) col = le

2020-11-28 18:15:06 133

原创 LC 旋转图像

LC 旋转图像1 先转置再按行反转class Solution: def rotate(self, matrix: List[List[int]]) -> None: """ Do not return anything, modify matrix in-place instead. """ n = len(matrix) for i in range(n): for j in ra

2020-11-27 21:30:51 133

原创 LC 有效的数独

LC 有效的数独字典(哈希表)出现错误的情况有:行标或列标一样,都属于大九宫格的同一小九宫格。创建一个字典,键为每个数的字符串形式,值为所在位置列表,通过比较位置列表判断有无重复。class Solution: def isValidSudoku(self, board: List[List[str]]) -> bool: dic = dict({}) for i in range(9): for j in range(9):

2020-11-27 16:26:48 125

原创 LC 两数之和(哈希表)

LC 两数之和(哈希表)1 两层循环class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: length = len(nums) i = 0 while i < length: for j in range(i+1,length): if nums[i]+nums[j] == tar

2020-11-27 12:10:33 77

原创 LC 两个数组的交集

LC 两个数组的交集给定两个数组,编写一个函数来计算它们的交集说明:输出结果中每个元素出现的次数,应与元素在两个数组中出现次数的最小值一致。可以不考虑输出结果的顺序。1字典记录次数,取次数小的构建新列表。class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: dic1 = dict({}) dic2 = dict({})

2020-11-26 15:04:29 98

原创 2020-11-25

给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。按位异或class Solution: def singleNumber(self, nums: List[int]) -> int: for i in range(1,len(nums)): nums[0] = nums[0] ^ nums[i] return nums[0]...

2020-11-25 18:59:48 86

原创 LC练习 存在重复元素

LC练习 存在重复元素1两个循环,时间复杂度n(n-1)/2,运行会超时。2二分递归查找class Solution: def containsDuplicate(self, nums: List[int]) -> bool: def tree(array): length = len(array) if length <= 1: return False

2020-11-25 16:43:56 79

原创 LC练习 旋转数组

LC练习 旋转数组1每次旋转一步,重复k次。可行,但是速度太慢了。class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ length = len(nums) for i in range(

2020-11-24 22:41:41 87

原创 LC练习 买卖股票的最佳时机

LC练习 买卖股票的最佳时机解答class Solution: def maxProfit(self, prices: List[int]) -> int: length= len(prices) i = 0 j = 1 profit = 0 while j <= length - 1: if prices[i] < prices[j]: i

2020-11-23 14:21:57 76

原创 LC练习 删除排序数组中的重复项

LC练习 删除排序数组中的重复项给定一个排序数组,你需要在 原地 删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成。第一次class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """

2020-11-23 09:23:49 133

原创 2020-11-21

space_to_depthtf.space_to_depth 函数space_to_depth(input, block_size, data_format=“NHWC”, name=None):SpaceToDepth for tensors of type T.重新排列空间数据块到depth维度。这个op输出一个输入张量的复制,使得 height和 width 维度的值转移到depth维度。 block_size表示输入的块大小。* 大小为 `block_size x block size

2020-11-22 13:57:20 71

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除