自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetcode 703 数字流中第k大的数字

题目:Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.Your KthLargest class will have a constructor...

2019-03-27 18:34:42 303

原创 leetcode 856 括号的分数

题目:Given a balanced parentheses string S, compute the score of the string based on the following rule:() has score 1AB has score A + B, where A and B are balanced parentheses strings.(A) has score...

2019-03-25 18:16:22 180

原创 leetcode 155 最小栈

题目:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Get ...

2019-03-23 19:59:43 167

原创 leetcode 844带空格的字符串比较

题目:Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.Example 1:Input: S = “ab#c”, T = “ad#c”Output: trueExplanation: B...

2019-03-23 15:06:55 260

原创 leetcode 82 删除有序链表的重复元素II

题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1-&gt...

2019-03-18 19:32:23 219

原创 leetcode 725将链表分割成几部分

题目:Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list “parts”.The length of each part should be as equal as possible: no two p...

2019-02-23 21:43:30 204

原创 leetcode 765夫妻握手

N couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people...

2019-02-15 12:47:44 174

原创 leetcode 402删除k个数字

题目:Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.Note:The length of num is less than 10002 and will be ≥ ...

2019-02-13 17:09:18 681

原创 leetcode 955以列为单位进行删除使得字符串数组有序

题目:We are given an array A of N lowercase letter strings, all of the same length.Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices.F...

2019-02-13 16:12:09 397

原创 leetcode 55跳跃游戏

题目:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if ...

2019-02-13 14:07:21 103

原创 Leetcode 134加油站

题目:There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to i...

2019-02-13 11:10:11 143

原创 leetcode 376. 摆动序列

题目:A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either ...

2019-02-13 08:59:30 342

原创 leetcode 649Dota2参议院

题目:In the world of Dota2, there are two parties: the Radiant and the Dire.The Dota2 senate consists of senators coming from two parties. Now the senate wants to make a decision about a change in the ...

2019-02-12 16:24:27 299 2

原创 leetcode 659连续数组分割子连续序列

You are given an integer array sorted in ascending order (may contain duplicates), you need to split them into several subsequences, where each subsequences consist of at least 3 consecutive integers....

2019-02-12 15:02:18 519

原创 leetcode 767重新分配字符串

题目:Given a string S, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same.If possible, output any possible result. If not possible, return t...

2019-02-12 11:58:21 272

原创 leetcode 738 单调递增数字位

题目:Given a non-negative integer N, find the largest number that is less than or equal to N with monotone increasing digits.(Recall that an integer has monotone increasing digits if and only if each p...

2019-02-12 10:38:07 352

原创 leetcode 870优点重排

题目:Given two arrays A and B of equal size, the advantage of A with respect to B is the number of indices i for which A[i] > B[i].Return any permutation of A that maximizes its advantage with resp...

2019-02-12 09:46:04 206

原创 leetcode 452用最少数量的箭头引爆箭头

题目:There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, y-coo...

2019-02-10 19:41:33 298

原创 leetcode 763字符串划分

题目:A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representin...

2019-02-10 19:00:00 260

原创 leetcode 984字符串贪心

题目:Given two integers A and B, return any string S such that:S has length A + B and contains exactly A ‘a’ letters, and exactly B ‘b’ letters;The substring ‘aaa’ does not occur in S;The substring ...

2019-02-10 15:59:49 209

原创 约数个数定理及其模板

原题目:输入n个整数,依次输出每个数的约数的个数,输入0表示输入结束定理介绍及其证明,对于一个大于1正整数n可以分解质因数:则n的正约数的个数就是 。其中a1、a2、a3…ak是p1、p2、p3,…pk的指数。证明:首先同上,n可以分解质因数:n=p1a1×p2a2×p3a3*…*pkak,由约数定义可知p1a1的约数有:p10, p1^1, p12…p1a1 ,共(a1+1)个;...

2019-02-09 08:16:04 526

原创 矩阵快速幂

1.基础知识储备篇矩阵的相关运算会再线性代数中学到。1.1矩阵的定义: N阶方阵(N阶矩阵):行数m与列数n相同的矩阵,如下图所示就是一个44的方阵:*行矩阵(行向量):只有一行的矩阵,下图就是一个行矩阵:​列矩阵(列向量):只有一列的矩阵,下图就是一个列矩阵:​同型矩阵:设先有矩阵A和矩阵B,矩阵A的行数与列数和矩阵B的相同,则矩阵A、B是同型矩阵。​单位矩阵:在矩阵的乘法...

2019-02-07 20:32:05 127

原创 求某天是当年的第几天

题目:给出年分m和一年中的第n天,算出第n天是几月几号。题解:import datetimewhile True:try:year, day = map(int, input().split())first_day = datetime.datetime(year, 1, 1)delta = datetime.timedelta(days=day - 1)print(dateti...

2019-02-07 18:29:26 228

原创 leetcode 4 求两个有序数组的中位数

题目:There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums1 and...

2019-02-07 11:18:14 69

原创 python 小数处理decimal模块

Python提供了decimal模块用于十进制数学计算,它具有以下特点:提供十进制数据类型,并且存储为十进制数序列;有界精度:用于存储数字的位数是固定的,可以通过decimal.getcontext().prec=x 来设定,不同的数字可以有不同的精度浮点:十进制小数点的位置不固定(但位数是固定的)decimal的构建:可以通过整数、字符串或者元组构建decimal.Decimal,对于...

2019-02-07 09:47:39 724

原创 python 小数错误处理总结

原代码版本:n1,n2=raw_input().split(’.’),raw_input().split(’.’)res=str(reduce(lambda a,b:10a+b,map(lambda x:ord(x[0])+ord(x[1])-2ord(‘0’),list(z_l(n1[-1][::-1],n2[-1][::-1],fillvalue=‘0’))[::-1])))c=1 if...

2019-02-07 09:47:11 1329

原创 leetcode 415 字符串相加

题目:Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is < 5100.Both num1 and num2 contains only digits 0...

2019-02-07 09:27:36 91

原创 leetcode 507 完美数

题目:We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns true when it is a per...

2019-02-06 19:24:58 230

原创 高效生成n个素数的方法

def primes(n):boo=[False]nboo[0],boo[1]=True,Truefor i in range(2,int(n*.5)+1):for j in range(2*i,n,i):boo[j]=Truereturn [p for p,v in enumerate(boo) if not v]

2019-02-06 16:18:52 416

原创 python技巧之一行代码转任意进制

def baseN(num,b):return ((num==0) and ‘0’) or (baseN(num/b,b).lstrip(‘0’)+‘0123456789ABCDEF’[num%b])

2019-02-06 12:24:17 458

原创 如何用牛顿迭代法求平方根

设函数y=f(x)在点x0的某个邻域内有定义,当自变量x在x0处有增量Δx,(x0+Δx)也在该邻域内时,相应地函数取得增量Δy=f(x0+Δx)-f(x0);如果Δy与Δx之比当Δx→0时极限存在,则称函数y=f(x)在点x0处可导,并称这个极限为函数y=f(x)在点x0处的导数记作①f’(x0) ;②y’│x=x0 ;③ │x=x0, 即导函数如果函数y=f(x)在开区间内每一点都可导,...

2019-02-06 11:23:44 5150

原创 leetcode 56 合并区间

题目:Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlap...

2019-02-05 09:29:57 110

转载 python 小数和gcd

1 基础Fraction类在Lib/fractions.py文件中,所以可以这样导入:?1from fractions import Fraction有很多种实例化Fraction类的方法。首先,你可以传入分子和分母:?12Fraction(1, 2)Fraction(1, 2)或者利用另一个分数进行实例化:?123f = Fraction(1,...

2019-02-04 12:41:13 272

原创 leetcode 394 编码字符串

题目:Given an encoded string, return it’s decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is ...

2019-02-02 17:58:16 157

原创 leetcode 473 用火柴棍组成正方形

题目:Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You s...

2019-02-02 17:56:39 301

原创 leetcode 778边下雨边游泳

On an N x N grid, each square grid[i][j] represents the elevation at that point (i,j).Now rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another...

2019-01-31 19:49:45 206

原创 leetcode 851 富有与安静

题目:In a group of N people (labelled 0, 1, 2, …, N-1), each person has different amounts of money, and different levels of quietness.For convenience, we’ll call the person with label x, simply “perso...

2019-01-31 19:02:33 1624

原创 leetcode 337 抢劫III

题目:The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After a ...

2019-01-31 16:57:14 515

原创 leetcode 638怎样购物最省钱

In LeetCode Store, there are some kinds of items to sell. Each item has a price.However, there are some special offers, and a special offer consists of one or more different kinds of items with a sal...

2019-01-31 15:21:20 222

原创 leetcode 864 获得钥匙的最短路径

题目:We are given a 2-dimensional grid. “.” is an empty cell, “#” is a wall, “@” is the starting point, (“a”, “b”, …) are keys, and (“A”, “B”, …) are locks.We start at the starting point, and one move...

2019-01-31 12:53:21 585

空空如也

空空如也

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

TA关注的人

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