自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Leetcode 5098. Tree Diameter

class Solution: def treeDiameter(self, edges: List[List[int]]) -> int: G=collections.defaultdict(list) for u,v in edges: G[u].append(v) G[v].append(u) ...

2019-11-03 10:24:50 250 1

原创 Golang踩坑之sort.Slice

import ( "fmt")func findRelativeRanks(nums []int){ index := []int{} for i := 0; i < len(nums);i++ { index=append(index,i) } // index // {0,1,2,3,4} sort.Slice...

2019-10-30 14:50:30 3699 1

原创 LCP3机器人大冒险

class Solution: def robot(self, command: str, obstacles: List[List[int]], x: int, y: int) -> bool: u,r=0,0 for m in command: if m=="U": u+=1 ...

2019-10-07 20:57:32 232

原创 Leetcode5091建造街区的最短时间

5091.建造街区的最短时间你是个城市规划工作者,手里负责管辖一系列的街区。在这个街区列表中blocks[i] = t意味着第 i个街区需要t个单位的时间来建造。由于一个街区只能由一个工人来完成建造。所以,一个工人要么需要再召唤一个工人(工人数增加 1);要么建造完一个街区后回家。这两个决定都需要花费一定的时间。一个工人再召唤一个工人所花费的时间由整数split给...

2019-09-22 08:34:07 479

原创 Leetcode636.函数的独占时间

# 2# ["0:start:0","1:start:2","1:end:5","0:end:6"]# 1# ["0:start:0","0:start:2","0:end:5","0:start:6","0:end:6","0:end:7"]# 2# ["0:start:0","0:start:2","0:end:5","1:start:6","1:end:6","0:end:7"]...

2019-09-16 14:23:29 213

原创 Leetcode 1191/5191 K 次串联后最大子数组之和

class Solution: def kConcatenationMaxSum(self, arr, k): """ :type arr: List[int] :type k: int :rtype: int """ res=0 most=0 n = len(...

2019-09-15 12:41:58 316

原创 Leetcode[1151]最少交换次数来组合所有的 1

"""1151. 最少交换次数来组合所有的 1 题目难度 Medium给出一个二进制数组 data,你需要通过交换位置,将数组中 任何位置 上的 1 组合到一起,并返回所有可能中所需 最少的交换次数。示例 1:输入:[1,0,1,0,1]输出:1解释: 有三种可能的方法可以把所有的 1 组合在一起:[1,1,1,0,0],交换 1 次;[0,1,1,1,0],交换 2 次...

2019-08-11 09:45:28 982

原创 [python]使用bits表示weekdays

在做表设计的时候,可能会遇到需要表示Weekdays的场景: {id:0, text:"Sun"}, {id:1, text:"Mon"}, {id:2, text:"Tue"}, {id:3, text:"Wed"}, {id:4, text:"Thu"}, {id:5, text:"Fri"}, ...

2019-06-17 16:24:59 450

原创 Leetcode 994. 腐烂的橘子

func orangesRotting(grid [][]int) int { /* 这题我学到了: 广度优先搜索的意义, 即矩阵中所有腐烂的橘子同时向四周扩张 */ R, C := len(grid), len(grid[0]) rotting := [][]int{} res := 0 for r := 0; r &l...

2019-06-03 17:57:55 428

原创 Leetcode 926. 将字符串翻转到单调递增

func minFlipsMonoIncr(S string) int { lo, hi := 0, len(S) - 1 zero, one := 0, 0 for _, c := range S { if c == '0' { zero++ }else{ one++ }...

2019-05-18 23:08:50 229

原创 Leetcode 955. 删列造序 II

func minDeletionSize(A []string) int { skip := map[int]bool{} m, n := len(A[0]), len(A) D := 0 for j := 0; j < m; j++ { cur := 0 index := []int{}...

2019-05-17 23:00:42 173

原创 Leetcode 219. 存在重复元素 II (3种解法:哈希表、排序、滑动窗口)

class Solution(object): def containsNearbyDuplicate(self, nums, k): # 哈希表 d = {} for i in range(len(nums)): if nums[i] in d: if -k <= i - d[...

2019-03-31 17:14:23 267

原创 Leetcode[149]直线上最多的点数

class Solution: def maxPoints(self, points): dup = collections.Counter([(p.x, p.y) for p in points]) pt = dup.keys() N = len(pt) res = 0 for i in range(N):...

2019-03-31 16:51:58 262

原创 Leetcode[849]到最近的人的最大距离

class Solution(object): def maxDistToClosest(self, seats): """ :type seats: List[int] :rtype: int """ N = len(seats) j, k = -1, -1 dp = [0]...

2019-03-28 12:56:42 227

原创 Leetcode[15]三数之和

class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ nums = sorted(nums) N = len(nums) i...

2019-03-27 21:59:58 1268

原创 Leetcode[39/40/216] combinationSum 三部曲

# coding:utf-8class Solution(object): def combinationSum(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] ...

2019-03-23 15:24:32 96

原创 Leetcode[442] 数组中重复的数据

'''442. 数组中重复的数据给定一个整数数组 a,其中1 ≤ a[i] ≤ n (n为数组长度), 其中有些元素出现两次而其他元素出现一次。找到所有出现两次的元素。你可以不用到任何额外空间并在O(n)时间复杂度内解决这个问题吗?示例:输入:[4,3,2,7,8,2,3,1]输出:[2,3]'''def findDuplicates(nums): res...

2019-03-22 14:34:14 94

原创 Leetcode 915. 分割数组

即使自己做了几遍,还是没有真正的开窍,领会精髓。第一眼看上去,这是一道数组分割的题目。 给定一个数组 A,将其划分为两个不相交(没有公共元素)的连续子数组 left 和 right, 使得:left 中的每个元素都小于或等于 right 中的每个元素。 left 和 right 都是非空的。 left 要尽可能小思路一:那么是按索引位置先分割,然后用暴力法比较?很容易...

2019-01-09 12:39:20 713

原创 算法题:对相交的圆进行分组(python)

# -*- coding: utf-8 -*-# 相交的圆'''问题2:假定二维空间平面内有n个圆,现在我们需要将存在`交集`的圆进行分组,输出结果为n个组,每个组包含i个圆. 交集算法: 两圆心的距离 小于 两圆半径之和. 假设圆数据为: (用数组表示圆) [ { X: 0, Y: 0, Radius: 1 }, { X: 3, Y: 2, Radius: ...

2018-10-10 23:04:19 1092

原创 LeetCode 794 Valid Tic-Tac-Toe State (Python)

class Solution(object): def validTicTacToe(self, board): """ :type board: List[str] :rtype: bool """ # count_x - count_o in [0,1] # only one reach...

2018-10-09 17:03:24 231

原创 Qualities of Coding

Qualities of CodingPositives收入:改善生活的物质条件(有多少比例的人是为了这个目的?我也是,但这是市场来决定。)高效:服务于许多人,有大量开发者或用户使用Negatives廉价:雇一个人就可以(能力不会比学历管用多少,反之如是,打工者始终是廉价的)低劣:缺乏一个远期的大目标,只是为了完成眼前的任务衰退:随着年龄的增长,体力和脑力都会下降...

2018-09-26 13:49:06 113

原创 魔术揭秘——所谓神级推理预测年龄

所谓神级推理预测年龄——即简单代数因式分解。 反向推理:思路:最后的呈现的数字,是一个3位数,比如 331(其实可以更多,但最后两位是必须要的)1、分解数字:331 = 3 x 100 + 31这里的“100”后面的“00”位置用来存放阁下的年龄number = n*100 + age2、计算年龄当前年份 current_year = 2018出生年份 bir...

2018-09-23 00:12:56 2989

原创 Leetcode 54 螺旋矩阵/59 螺旋矩阵II Golang

54 螺旋矩阵func spiralOrder(matrix [][]int) []int { if len(matrix) == 0 { return []int{} } R, C := len(matrix), len(matrix[0]) visited := make([][]int, R) for r := 0; r <...

2018-09-22 15:58:29 785

原创 Leetcode 61. 旋转链表 Python

我的版本:# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def rotateRight(self,...

2018-09-20 15:13:33 420

原创 Python转换字典成为对象,可以用"."方式访问对象属性

database = [ { "name": "18D_Block", "xcc":{ "component": { "core":[], "platform":[] }, }, "uef

2018-09-19 14:31:11 9239

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

class Solution: def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ rm=0 dup=0 L = len(nums) lo = 0 ...

2018-09-17 13:44:07 405

原创 python笔试题之找出一个列表里出现频次最高的元素(most common elements in a list)

def most_common(seq): d = {} for i in seq: d[i] = d.get(i, 0) + 1 ret = [] for j in sorted(d.items(), reverse=True, key=lambda x:x[1]): if len(ret) == 0: ret

2016-09-24 18:55:20 6528

原创 测试python装饰器decorator

# coding=utf-8# 主题:测试python装饰器的一些特性def outter(f): print 'it is outter.' def wrapper(): return f return wrapper()def end(f): print 'it is end' print f('call it') def

2015-09-13 11:43:25 709

原创 Python面试题 之 Uniquify a list 不使用set去除一个列表中的重复项,并且保持原有的排列顺序

def uniquify_a_list(ls): _ = lambda e, ls=[] : None if e in ls else ls.append(e) or ls return map(_, ls)[0] def uniquify_a_sorted_list(ls): # two pointers solution (learn from Leet...

2015-09-10 11:32:14 913

原创 在一个list列表中的多个dict字典按照键值对key-value来进行排序

# -*- coding: utf-8 -*-#主题:在一个list列表中的多个dict字典按照键值对key-value来进行排序items = [ {'name':'李四','age':40}, {'name':'张三','age':30}, {'name':'王五','age':50},]items0 = items[:]# list.sort()或者sort

2015-09-02 23:15:03 7967

原创 python闭包实现,匿名函数的实现

#!/usr/bin/env python#coding=utf-8# python实现闭包def wrapper(counter={'cnt':0}): def _closure(): counter.update({ 'cnt':counter.get('cnt') + 1 }) return counter['cnt'] return _closure# 匿名

2015-09-01 14:20:04 395

原创 sublime text 3-Virtualenv-Anaconda配

[projectname].sublime-project:{                   "settings": {                "python_interpreter": "~/workspace/env/bin/python",                "test_command": "./manage.py test --settings

2015-08-12 22:35:28 2069

空空如也

空空如也

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

TA关注的人

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