自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

翻译 Linked List Cycle II

题目详情:https://leetcode.com/problems/linked-list-cycle/description/ 题目详情:https://leetcode.com/problems/linked-list-cycle-ii/description/这篇博客(http://www.cnblogs.com/hiddenfox/p/3408931.html)写的不错,从解题的思路,到

2017-07-31 18:39:41 293

原创 Single Number

题目详情:https://leetcode.com/problems/single-number/description/# -*- coding:utf-8 -*-class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: i

2017-07-31 13:16:16 212

原创 Valid Palindrome

题目详情:https://leetcode.com/problems/valid-palindrome/description/ 自己写的代码,运行时间有点长啊,715ms,[衰]class Solution(object): def isPalindrome(self, s): """ :type s: str :rtype: bool

2017-07-31 11:38:04 318

原创 Best Time to Buy and Sell Stock II

题目详情:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/ 问题考虑什么时候决定将股票售出?就想到了前后差值反应了股票的变化,然后 [7,1,5,3,6,4]做差值后得[-6,4,-2,3,-2]突然意识到前后差值的正数只和就是所求。class Solution(object): d

2017-07-30 23:35:18 259

原创 Best Time to Buy and sell Stock

题目详情:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int

2017-07-30 16:35:28 291

原创 Pascal Triangle II

题目详情:https://leetcode.com/problems/pascals-triangle-ii/description/#-*- coding: UTF-8 -*-class Solution(object): def getRow(self, rowIndex): """ :type rowIndex: int :rtype:

2017-07-30 16:28:34 269

原创 Pascal's Triangle

题目详情:https://leetcode.com/problems/pascals-triangle/description/class Solution(object): def generate(self, numRows): """ :type numRows: int :rtype: List[List[int]] "

2017-07-30 11:08:04 241

原创 Path Sum

题目详情:https://leetcode.com/problems/path-sum/description/ 本题中设置isLeaf的原因是避免出现[1,2],sum=1的情况,即必须是从根节点到叶子节点。# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):#

2017-07-29 18:00:40 279

原创 Convert Sorted Array to Binary Search Tree

题目详情:https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/tabs/descriptionclass Solution(object): def sortedArrayToBST(self, nums): """ :type nums: List[int]

2017-07-28 21:39:42 271

原创 Binary Tree Level Order Traversal II

题目详情:https://leetcode.com/problems/binary-tree-level-order-traversal-ii/tabs/description提交的时候,出现了Line 51: AttributeError: ‘Solution’ object has no attribute ‘levelOrderBottom’。不知道是为什么。后来一点点的复制过去才解决的。还删

2017-07-28 18:13:08 301

原创 Minimum Depth of Binart Tree

题目详情:https://leetcode.com/problems/minimum-depth-of-binary-tree/tabs/description/ 该题与求树的深度不太一样,原因是求从根节点到叶子节点的最短路径。 思路:每次递归,当前节点到根节点的深度恰好递归的深度,所以设置变量now用以记录递归的深度(也就是节点的深度),每次都判断该节点是否为叶子节点,若为叶子节点在判断当前叶

2017-07-28 17:04:33 308

原创 Binary Tree Level Order Traversal

题目详情:https://leetcode.com/problems/binary-tree-level-order-traversal/tabs/description/#-*- coding: UTF-8 -*-# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):

2017-07-28 13:19:49 249

原创 Maximum Depth of Binary Tree

题目详情:https://leetcode.com/problems/maximum-depth-of-binary-tree/tabs/description/class Solution(object): def maxDepth(self, root): """ :type root: TreeNode :rtype: int

2017-07-28 10:43:04 314

原创 Symmetric Tree

题目详情:https://leetcode.com/problems/symmetric-tree/tabs/description/ 方法一: 1、通过后续遍历,建立一棵树,该树为原树的对称树 2、比较两棵树是否相等# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x

2017-07-27 23:24:56 295

原创 Git-分支管理

1、分支冲突 当在分支里改变了某个文件,然后又在master分支里修改了文件,那么在master分支里,合并分支的时候会出现错误,Auto-merging README.mdCONFLICT (content): Merge conflict in README.mdAutomatic merge failed; fix conflicts and then commit the result

2017-07-27 17:32:44 424

原创 Same Tree

题目详情:https://leetcode.com/problems/same-tree/tabs/description …如果p和q都不为空: ………继续检查p和q的值是否相等, ……………值也相等,则检查左右子树 ………如果值不等,则直接返回假值 …如果p和q都为空的话,返回相等的真值 …其余的情况返回假值class Solution(object): def isSame

2017-07-27 12:14:41 281

原创 Merge Sorted Array

题目详情:https://leetcode.com/problems/merge-sorted-array/#/description 我感觉这道题没什么好说的,简单粗暴。#-*- coding: UTF-8 -*-class Solution(object): def merge(self, nums1, m, nums2, n): """ :type

2017-07-26 21:01:16 224

原创 Remove Duplicates from Sorted List

题目详情:https://leetcode.com/problems/remove-duplicates-from-sorted-list/#/description 一遍就ac了class Solution(object): def deleteDuplicates(self, head): """ :type head: ListNode

2017-07-26 14:57:27 256

原创 Git-创建与合并分支

1、创建分支,branchName表示要创建的分支的名字git branch branchName2、从当前分支切换到另一分支,例如当前分支为master分支,切换到master1分支git checkout master13、创建分支并且切换到新创建的分支git checkout -b branchName4、列出所有的分支,并且当前分支的前边会有”*”表示git branch5、合并分支git

2017-07-26 08:21:31 287

原创 Climbing Stairs

题目详情:https://leetcode.com/submissions/detail/111073632/ 暴力破解,会超时!class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int """ return s

2017-07-26 00:10:19 266

原创 Hadoop安装,伪分布式配置

操作系统:MacOS Sierra 10.12.4 1、下载Hadoop。使用brew下载Hadoop,命令为brew install Hadoop 。默认安装为最新的Hadoop版本,截止2017-7-23日最新的版本为Hadoop 2.8.0。安装目录为/usr/local/cellar/hadoop/2.8.0。2、需要配置java的安装目录,但是brew 安装java时,已经配置好了。所以

2017-07-23 18:38:28 389

原创 Sqrt(x)

题目详情:https://leetcode.com/problems/sqrtx/#/description 用的牛顿迭代法, 1、计算sqrt(x) = n的解,两边同时平方得:x=n*n,移项得n*n-x=0 ,令f(n)=n*n-x,相当于求解f(x)=0的解。 2、首先取x0,如果x0不是解,做一个经过(x0,f(x0))这个点的切线,与x轴的交点为x1。 3、同样的道理,如果x1

2017-07-20 23:43:57 425

原创 Add Binary

模拟二进制数的加法操作过程class Solution(object): def addBinary(self, a, b): """ :type a: str :type b: str :rtype: str """ length=0 i=len(a)-1 j=l

2017-07-20 11:35:29 407

原创 Plus One

题目详情:https://leetcode.com/problems/plus-one/#/description Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. 给一个非负整数,相当于一个非空数组中的各个数字,对这一个非负整数加一。You may

2017-07-19 17:56:46 305

原创 Git-远程仓库

1、注册GitHub账号,并建立一个远程仓库,但是这个仓库是空的,可以把一个已有的本地仓库与之关联,然后把本地仓库的内容推送到该GitHub仓库。命令git remote add origin GitHub-address注意:一定要在要关联的仓库目录下执行该条命令,表示将本地仓库和远程仓库(GitHub-address)相关联。 2、下一步就可以把本地库的内容推送到远程库上,命令:git pus

2017-07-19 11:44:12 307

原创 Length of Last World

题目详情:https://leetcode.com/problems/length-of-last-word/#/description 这是自己写的,运行时间289ms[衰]。int lengthOfLastWord(char* s){ int len=0; for(int i=0;i<strlen(s);++i) { if( s[i]==' ' ) {

2017-07-18 23:13:10 230

原创 Maximum Subarray

解法一(动态规划)、 设置两个变量分别是location,largeSum,其初始值都为数组的首元素。location为局部的最优解,largeSum为全局的最优解。 1、当整数集合中只有一个元素的时候,那么子串就是该元素 2、当有两个元素的时候,例如(n1,n2): 若最大子串为(n2)或者为(n1,n2),则最优子串和为location=largeSum=n2或者location=lar

2017-07-18 18:20:04 407

原创 Count and Say

题目详情:https://leetcode.com/submissions/detail/109725252/ 关键在于理解题目的意思,当n=1时,str=”1”;n=1时,字符串只有1个1,所以当n=2时,str=”11”;n=2时,有2个1,所以n=3时,str=”21”;n=3时,有1个2,1个1,所以n=4时,str=”1211”;一次类推。 python代码如下:class Solut

2017-07-15 18:38:49 418

原创 Search Insert Position

题目描述:https://leetcode.com/submissions/detail/109722899/int searchInsert(int* nums, int numsSize, int target){ int i=0; for(;i<numsSize;++i) { if ( target <= nums[i]) //如果在某一个位置nums[i]>=targe

2017-07-15 17:32:01 267

原创 implement strStr()

c语言暴力破解:int strStr(char* haystack, char* needle){ int i=0,j=0; for( i=0;haystack[i]!='\0';++i) { int t=i; //记录下i的位置 for( j=0;needle[j]!='\0';++j) { if (haystack[i] != needle[j

2017-07-15 13:14:01 378

原创 Remove Element

这道题用python写真方便啊!就是运行时间有点长啊!class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ index

2017-07-14 22:56:45 308

原创 Remove Duplicates from Sorted Array

一定要看懂题啊!看懂题的关键是英语好! 一定要看懂题啊!看懂题的关键是英语好! 一定要看懂题啊!看懂题的关键是英语好! 一开始没有看懂题,只返回了无重复元素数组的长度,结果错了。数组中前length个元素也必须是有序的。int removeDuplicates(int* nums, int numsSize){ if( numsSize < 2 ) return nums

2017-07-14 18:13:49 159

原创 Git-管理修改

情景1、如果修改了工作区某个文件的内容,想直接放弃对工作区的修改,可以使用git checkout -- file (两个连字符后有个空格) (1)、修改后的内容还没有添加到暂存区,那么撤销之后,就回到和版本库一模一样的状态了。 (2)、对文件的修改已经添加到暂存区了,然后又做了修改,但是对第二次的修改还没有添加到暂存区,那么撤销修改后就回到了和暂存区一样的状态了。情景2、对文

2017-07-14 16:22:07 237

原创 Git-管理版本

1、我们对test目录下的readme.txt文件添加新的内容,然后通过git status 查看当前test仓库的状态。注意一定要在test目录下,运行该命令。可以看到readme.txt文件已经被修改了,但是并没有告诉我们具体的修改。可以通过git diff 命令来查看。通过git add filename 和git commit -m "information" 命令提交到版本库中。2、通过g

2017-07-14 12:33:23 217

原创 Git-创建版本库

首先需要下载git。 1、在你的电脑上选择一个合适的目录,运行mkdir test建立一个名为test的空文件夹 2、在shell中进入该文件夹,运行git init 命令,把这个目录变成git可以管理的仓库。 通过以上两个步骤就建立了一个仓库(版本库)。 3、在test目录下建立一个readme.txt的文件(可以通过touch readme.txt 命令建立),并编辑相关内容,存储。

2017-07-14 11:19:59 494

原创 Merge Two Sorted Lists

这道题感觉很简单,以前做过好几遍类似的题目(用c语言写),结果现在用python写却花了好长时间。 (python版本)# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Non

2017-07-13 17:37:39 232

原创 Valid Parentheses

题目要求:输入一个字符串判断括号是否匹配。感觉做简单题,主要考查英语水平[衰]。class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ stack=[] #用list数据类型构造模拟栈 for

2017-07-09 10:02:12 176

原创 Long Common Prefix

class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if len(strs)==0: #字符串的个数为0 return ""

2017-07-09 00:00:26 281

原创 Roman to Integer

罗马数字中基本数字:Ⅰ(1)、X(10)、C(100)、M(1000)、V(5)、L(50)、D(500)。 组成数的规则: 1、相同的数字连写,所表示的数等于这些数字相加得到的数,如 Ⅲ=3; 2、小的数字在大的数字的右边,所表示的数等于这些数字相加得到的数,如 Ⅷ=8、Ⅻ=12; 3、小的数字(限于 Ⅰ、X 和 C)在大的数字的左边,所表示的数等于大数减小数得到的数,如 Ⅳ=4、Ⅸ=9;

2017-07-08 18:04:22 218

原创 Reverse Integer

本题不难,主要是为了练习用python。 1、首先分离x各个位上的数 2、将分离的各个位的数按照要求重新组成一个新数,即逆序数 3、判断是否超出32位数的范围,然后按照要求进行输出即可 完整代码如下:class Solution(object): def reverse(self, x): """ :type x: int :rtype

2017-07-06 22:39:36 275

空空如也

空空如也

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

TA关注的人

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