自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 LeetCode:Pascal's Triangle II

题目:Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1]解题思路:由于只需要返回第k行的帕斯克三角,所以用一个数组p储存。帕斯克三角: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1可以看出:a[i][j]=a[i-1]

2016-05-19 12:30:01 212

转载 LeetCode:Plus One

题目:给定一个数组,数组每一位为个位数。将数组所组成的数+1,再返回数组。例:input=[9,9] output=[1,0,0]解题思路:将数组转换成整数,加一后再将整数转换为数组。代码:class Solution(object): def plusOne(self,digits): """ :type digits: List[int] :rtype: List

2016-05-18 18:18:49 177

转载 LeetCode: Best Time to Buy and Sell Stock

题目:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), d

2016-05-16 22:58:48 212

原创 LeetCode: Number of 1 Bits

题目:Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11’ has binary representation 0000000000

2016-05-16 09:54:52 194

转载 Leetcode: Roman to integer

题目:将罗马数字转换成整数,输入范围:[1,3999]解题思路:罗马数字与阿拉伯数字对应关系:1~9: {“I”, “II”, “III”, “IV”, “V”, “VI”, “VII”, “VIII”, “IX”};10~90: {“X”, “XX”, “XXX”, “XL”, “L”, “LX”, “LXX”, “LXXX”, “XC”};100~900: {“C”, “CC”, “CCC”,

2016-05-14 11:53:00 183

原创 Leetcode:Product of Array Except Self

题目:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).Fo

2016-05-13 10:36:33 255

原创 Leetcode:Counting Bits

题目:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you

2016-05-11 10:48:14 244

原创 Leetcode:Maximum Product of Word Lengths

题目:Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le

2016-05-10 16:43:34 493

原创 LeetCode: Excel Sheet Column Title

题目:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB 解题思路:10进制转26进制几个注意点:1.如何将数字转换成字符:使用指令chr(字

2016-05-06 19:59:22 643

原创 LeetCode: Valid Anagram

题目:给定两个字符串s和t,写出一个程序判断s是否为t的回文字符串。例:s=”anagram”, t=”nagaram” 返回trues=”car”, t=”ant” 返回false解题思路1:使用sorted函数,将字符串排序,如:sorted(s)=[‘a’,’a’,’a’,’g’,’m’,’n’,’r’],sorted(t)=[‘a’,’a’,’a’,’g’,’m’,’n’,’r’]代码1:

2016-05-06 10:36:53 445

原创 LeetCode:Single Number 3

题目大意:给定一个整数数组,其中除两个数字只出现一次外,其余数字均出现两次。找出这两个只出现一次的数字。例如:给定 nums = [1, 2, 1, 3, 2, 5],返回 [3, 5]注意:结果的顺序不重要。因此在上例中,[5, 3]也是正确的。你的算法应该满足线性时间复杂度。你可以只使用常数空间复杂度完成题目吗?解题思路1:使用字典,利用语句:dic[num]=dic.get(num,0)+1

2016-05-05 21:22:17 280

原创 LeetCode: Move Zeros

题目:给出一个数组nums,编写函数将数组内所有0元素移至数组末尾,并保持非0元素相对顺序不变。例如,给定nums = [0, 1, 0, 3, 12],调用函数完毕后, nums应该是 [1, 3, 12, 0, 0]。解题思路1:使用两个”指针”x和y,初始令y = 0;利用x遍历数组nums:若nums[x]非0,则交换nums[x]与nums[y],并令y+1代码:class Solutio

2016-05-05 15:02:46 242

原创 LeetCode: Single Number

LeetCode: Single Number题目:给一组整数,除了一个元素外,其余元素全部出现两次,找到只出现一次的元素并输出。解题思路:使用异或的性质:(1)A^A=0 (2)异或满足交换律:A^B^C^A^B=A^A^B^B^C=C参考:[异或说明](https://www.lijinma.com/blog/2014/05/29/amazing-xor/)代码:class Solution(

2016-05-05 10:27:25 186

空空如也

空空如也

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

TA关注的人

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