10 2014 档案
摘要:octave:14> help plot'plot' is a function from the file C:\Octave\Octave3.6.4_gcc4.6.2\share\octave\3.6.4\m\plot\plot.m -- Function File: plot (Y) -- ...
阅读全文
摘要:前提是你已经在机器上安装了python~并且你的机器能够上网~1、进入:https://bootstrap.pypa.io/get-pip.py,ctrl+s保存网页(其实是.py文件)到某一目录;2、打开命令行,进入1中的目录;3、输入命令:python get-pip.py之后它自己会下载pip...
阅读全文
摘要:1、类中递归调用添加self;2、root为None,返回03、root不为None,root左右孩子为None,返回14、返回l和r最小深度,l和r初始为极大值; 1 # Definition for a binary tree node 2 # class TreeNode: 3 # ...
阅读全文
摘要:1、类中递归调用函数需要加self# Definition for a binary tree node# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# ...
阅读全文
摘要:1、p或q为None的情况用开始的两个if语句进行判断;2、类中递归调用函数需要使用self进行调用;3、代码很简洁,最后几行通过同时为None和同时非None的条件进行判断; 1 # Definition for a binary tree node 2 # class TreeNode: 3 ...
阅读全文
摘要:1、用双重循环逐个遍历(超时)2、用list B的append和remove函数(超时)3、用dict B(AC) 1 class Solution: 2 # @param A, a list of integer 3 # @return an integer 4 def s...
阅读全文
摘要:1、当strs为空,直接输出“”2、当strs中含有“”,直接输出“”3、strs[0]的最长长度由最短公共长度l决定(code line:15) 1 class Solution: 2 # @return a string 3 def longestCommonPrefix(sel...
阅读全文
摘要:一次AC题目要求中有空间限制,因此没有采用字符串由量变向中间逐个对比的方法,而是采用计算翻转之后的数字与x是否相等的方法; 1 class Solution: 2 # @return a boolean 3 def isPalindrome(self, x): 4 o...
阅读全文
摘要:一次AC字符串就是:count+char 1 class Solution: 2 # @return a string 3 def countAndSay(self, n): 4 str = "1" 5 for i in range(n-1): 6 ...
阅读全文
摘要:1、在进入while之前,保证x是非负的;2、符号还是专门用flag保存===================3、另一思路:将integer转换成string,然后首位swap,直至中间; 1 class Solution: 2 # @return an integer 3 def ...
阅读全文
摘要:#error caused by:#1:{} 没有考虑None输入#2:{1,2,2} 没有控制h和t#3:{4,-57,-57,#,67,67,#,#,-97,-97} 没有考虑负号,将s从str变成list,采用9999代表空数值;---------------------逐层进行对称性验证,...
阅读全文
摘要:1、将tri初始化为[1],当rowIndex=0时,return的结果是:1,而题目要求应该是:[1],故将tri初始化为[[1]],返回结果设置为tri[0]即可满足要求;2、最开始第二层循环是从1到i进行遍历,这样就不好控制数据的更新,因为更新第j个数据要用到原tri行的第j-1个数据,而此时...
阅读全文
摘要:1、这道题一次提交就AC了;2、以前用C语言实现的话,初始化二维数组全部为0,然后每行第一个元素为1,只需要用a[i][j] = a[i-1][j]+a[i-1][j-1]就可以了;3、在Python中难点应该就是每行的第一个元素和最后一个元素,最后一个元素通过判断j==i就可以区分了; 1 cla...
阅读全文
摘要:1、注意空字符串的处理;2、注意是alphanumeric字符;3、字符串添加字符直接用+就可以; 1 class Solution: 2 # @param s, a string 3 # @return a boolean 4 def isPalindrome(self, ...
阅读全文
摘要:# Definition for a binary tree node# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right ...
阅读全文
摘要:1 class Solution: 2 # @param s, a string 3 # @return a string 4 def reverseWords(self, s): 5 ss = s.split(" ") 6 ss = fil...
阅读全文
摘要:19.7. xml.etree.ElementTree — The ElementTree XML API源代码: Lib/xml/etree/ElementTree.pyElement类型是一种灵活的容器对象,用于在内存中存储层次数据结构。可以说是list和dictionary的交叉。注意:xml...
阅读全文