自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

转载 小项目——图转

import numpy as npimport mathimport cv2img_name = '/home/thugliu/2.jpeg'img = cv2.imread(img_name)img = wrapped_img = cv2.resize(img,None,fx=2,fy=2,interpolation=cv2.INTER_CUBIC)# 准备工作,计算原图像尺寸和变...

2019-07-16 23:33:13 130

原创 137. 只出现一次的数字 II

class Solution: def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ return (3*sum(set(nums)) - sum(nums))//2

2019-01-21 16:25:22 117

原创 136. 只出现一次的数字

from functools import reduce #reduce() 函数会对参数序列中元素进行累积。from operator import xorclass Solution: def singleNumber(self, nums): """ :type nums: List[int] :rtype: int ...

2019-01-21 16:15:28 96

原创 134. 加油站

class Solution: def canCompleteCircuit(self, gas, cost): """ :type gas: List[int] :type cost: List[int] :rtype: int """ res, all_sum, min_sum = -1,...

2019-01-19 15:26:19 131

原创 131. 分割回文串

class Solution: def partition(self, s): """ :type s: str :rtype: List[List[str]] """ results = [[s[0]]] for c in s[1:]: for r in result...

2019-01-19 15:21:36 111

原创 130. 被围绕的区域

class Solution: def solve(self, board): """ :type board: List[List[str]] :rtype: void Do not return anything, modify board in-place instead. """ if not boa...

2019-01-19 14:38:46 88

原创 小项目——马赛克风格迁移

最近一直想做一个质量较高的涂鸦作品,但迫于非科班出生加上控瓶能力有限无法处理好图像细节,于是用python助力艺术,将原图画风迁移成马赛克风格。9行代码,内容不多也没什么好讲解的,用过相关库的同志们肯定懂,就当看看涂鸦作品吧:)import numpy as npimport matplotlib.pyplot as plt%matplotlib inlineimg = plt.imrea...

2019-01-06 00:25:11 227

原创 129. 求根到叶子节点数字之和

# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def sumNumbers(s...

2018-12-18 21:45:54 165

原创 127. 单词接龙

class Solution: def ladderLength(self, beginWord, endWord, wordList): """ :type beginWord: str :type endWord: str :type wordList: List[str] :rtype: int ...

2018-12-18 21:31:09 141

原创 125. 验证回文串

class Solution: def isPalindrome(self, s): """ :type s: str :rtype: bool """ s = list(filter(str.isalnum, s.lower())) return True if s == s[::-1] e...

2018-12-18 20:57:05 95

原创 122. 买卖股票的最佳时机 II

class Solution: def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ profit = 0 for i in range(1,len(prices)): if p...

2018-12-18 16:27:28 95 1

原创 121. 买卖股票的最佳时机

class Solution: def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ if len(prices) < 2: return 0 minimum = pric...

2018-12-18 16:25:44 93

原创 120. 三角形最小路径和

class Solution: def minimumTotal(self, triangle): """ :type triangle: List[List[int]] :rtype: int """ if not triangle: return ans = tri...

2018-12-18 16:21:43 104

原创 119. 杨辉三角 II

class Solution: def getRow(self, rowIndex): """ :type rowIndex: int :rtype: List[int] """ ans = [] for i in range(rowIndex+1): temp = [...

2018-12-18 16:05:42 116

原创 118. 杨辉三角

class Solution: def generate(self, numRows): """ :type numRows: int :rtype: List[List[int]] """ ans = [] for i in range(numRows): temp ...

2018-12-18 15:54:42 80

原创 114. 二叉树展开为链表

class Solution: def flatten(self, root): """ :type root: TreeNode :rtype: void Do not return anything, modify root in-place instead. """ if root == None: ...

2018-12-17 20:47:31 89

原创 小项目——训练画风数据集

上篇

2018-12-14 11:22:05 349

原创 100. 相同的树

class Solution: def isSameTree(self, p, q): """ :type p: TreeNode :type q: TreeNode :rtype: bool """ if p==None and q==None: return Tru...

2018-12-13 15:35:50 107

原创 98. 验证二叉搜索树

class Solution: def isValidBST(self, root): """ :type root: TreeNode :rtype: bool """ if not root: return True pre = None stac...

2018-12-13 15:33:47 159

原创 96. 不同的二叉搜索树

class Solution: def numTrees(self, n): """ :type n: int :rtype: int """ mem = [0]*(n+1) mem[0], mem[1] = 1, 1 for i in range(2, n ...

2018-12-13 15:23:18 94 1

原创 95. 不同的二叉搜索树 II

class Solution: def generateTrees(self, n): """ :type n: int :rtype: List[TreeNode] """ if n == 0: return list() mem = dict() r...

2018-12-11 16:44:19 114

原创 94. 二叉树的中序遍历

class Solution: def inorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ if root == None: return [] ans = [] ...

2018-12-11 16:24:16 72 1

原创 93. 复原IP地址

class Solution: def restoreIpAddresses(self, s): """ :type s: str :rtype: List[str] """ if len(s) > 12: return [] res = [] s...

2018-12-11 15:52:26 80

原创 92. 反转链表 II

class Solution: def reverseBetween(self, head, m, n): """ :type head: ListNode :type m: int :type n: int :rtype: ListNode """ if head == No...

2018-12-11 15:34:24 87

原创 91. 解码方法

class Solution: def numDecodings(self, s): """ :type s: str :rtype: int """ if s=="" or s[0]=='0': return 0 dp=[1,1] for i in range(2,len(s...

2018-12-11 15:02:02 191

原创 小项目——自制画风数据集

承接上篇爬取了想要的数据集之后,先将图片的尺寸统一。(我自己爬取了涂鸦,油画,素描这3类图片)# coding=utf-8from PIL import Imageimport os.pathimport globdef convertjpg(jpgfile,outdir,width=256,height=256): img=Image.open(jpgfile) try...

2018-12-10 21:39:50 1113

原创 90. 子集 II

class Solution: def subsetsWithDup(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ ans = [] nums.sort() self.dfs(nums,0,...

2018-12-10 16:45:01 60

原创 88. 合并两个有序数组

class Solution: def merge(self, nums1, m, nums2, n): """ :type nums1: List[int] :type m: int :type nums2: List[int] :type n: int :rtype: void Do no...

2018-12-10 16:03:18 95

原创 86. 分隔链表

# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def partition(self, head, x): """ ...

2018-12-10 16:00:22 64

原创 83. 删除排序链表中的重复元素

# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def deleteDuplicates(self, head): ""...

2018-12-10 15:47:50 45

原创 82. 删除排序链表中的重复元素 II

# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def deleteDuplicates(self, head): ""...

2018-12-10 15:39:18 77

原创 81. 搜索旋转排序数组 II

class Solution: def search(self, nums, target): """ :type nums: List[int] :type target: int :rtype: bool """ pol = len(nums)-1 while pol&gt...

2018-12-09 16:15:09 69

原创 80. 删除排序数组中的重复项 II

class Solution: def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ i,num = 2,len(nums) while i < num: if nu...

2018-12-09 15:51:49 43

原创 79. 单词搜索

class Solution: def exist(self, board, word): """ :type board: List[List[str]] :type word: str :rtype: bool """ for y in range(len(board)): ...

2018-12-09 15:33:38 61

原创 78. 子集

class Solution: def subsets(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ self.res=[] def dfs(nums, temp, i): self...

2018-12-09 15:03:32 81

原创 77. 组合

class Solution: def _combine(self, n, k, start, nums, res): if len(nums) == k: res.append(nums.copy()) return for i in range(start, n+1): ...

2018-12-09 14:25:16 93 2

原创 75. 颜色分类

也不用什么双指针了蛮无聊的class Solution: def sortColors(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ ..

2018-12-08 16:47:29 184

原创 74. 搜索二维矩阵

class Solution(object): def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ if not matrix ...

2018-12-08 16:17:37 74

原创 73. 矩阵置零

class Solution: def setZeroes(self, matrix): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """ pos...

2018-12-08 16:03:59 58

原创 70. 爬楼梯

class Solution: def climbStairs(self, n): """ :type n: int :rtype: int """ condition = [0] * (n + 1) condition[0] = 1 condition[1] = 1 ...

2018-12-08 15:56:30 59

空空如也

空空如也

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

TA关注的人

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