12 2017 档案

摘要:Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: (1)思想1:使用queue ,对二叉树进行层遍历。 C++: 阅读全文
posted @ 2017-12-18 22:07 西瓜刀刀刀 阅读(108) 评论(0) 推荐(0)
摘要:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpo 阅读全文
posted @ 2017-12-18 21:47 西瓜刀刀刀 阅读(103) 评论(0) 推荐(0)
摘要:Given a 32-bit signed integer, reverse digits of an integer. Example 1: Example 2: Example 3: Note:Assume we are dealing with an environment which cou 阅读全文
posted @ 2017-12-15 10:19 西瓜刀刀刀 阅读(126) 评论(0) 推荐(0)
摘要:1.*args args是非关键字参数,可以理解为形参,为了方便记忆我理解它是arguments的缩写。 2.*kwargs kwargs是键值对参数,为了方便记忆我理解它是key word arguments的缩写。 3.setattr() set是设置,attr是属性,综合起来就是设置属性的函数 阅读全文
posted @ 2017-12-14 20:37 西瓜刀刀刀 阅读(1496) 评论(0) 推荐(0)
摘要:数字转换成字符串: num=123 str='%d' %num str就变成了"123" 阅读全文
posted @ 2017-12-14 16:34 西瓜刀刀刀 阅读(5563) 评论(0) 推荐(0)
摘要:返回真假时,需要为: return True return False 阅读全文
posted @ 2017-12-14 16:24 西瓜刀刀刀 阅读(7779) 评论(0) 推荐(0)
摘要:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thi 阅读全文
posted @ 2017-12-14 16:23 西瓜刀刀刀 阅读(143) 评论(0) 推荐(0)
摘要:排序并且改变自身结果: nums.sort() 阅读全文
posted @ 2017-12-14 16:05 西瓜刀刀刀 阅读(168) 评论(0) 推荐(0)
摘要:Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected e 阅读全文
posted @ 2017-12-14 16:02 西瓜刀刀刀 阅读(226) 评论(0) 推荐(0)
摘要:vector<int> v: 最大值: int max = *max_element(v.begin(),v.end()); 最小值: int min = *min_element(v.begin(),v.end()); 阅读全文
posted @ 2017-12-14 11:31 西瓜刀刀刀 阅读(23958) 评论(0) 推荐(1)
摘要:Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n  阅读全文
posted @ 2017-12-14 11:29 西瓜刀刀刀 阅读(242) 评论(0) 推荐(0)
摘要:A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128 阅读全文
posted @ 2017-12-14 11:11 西瓜刀刀刀 阅读(161) 评论(0) 推荐(0)
摘要:定义一个字符串,求其长度: string str; str.length(); str.size(); 阅读全文
posted @ 2017-12-14 09:41 西瓜刀刀刀 阅读(1861) 评论(0) 推荐(0)
摘要:头文件:<string> 转换函数:to_string(); 例如:int n=10; string str=to_string(n) ; 阅读全文
posted @ 2017-12-14 09:32 西瓜刀刀刀 阅读(634) 评论(0) 推荐(0)
摘要:map函数: 接受一个函数 f 和一个 list 。格式:map( f , L),对L中的每个元素,进行f(x)的一个操作。 例如,对于list [1, 2, 3, 4, 5, 6, 7, 8, 9],如果希望把list的每个元素都作平方,就可以用map()函数: 此时,结果就为:[1, 4, 9, 阅读全文
posted @ 2017-12-13 21:54 西瓜刀刀刀 阅读(178) 评论(0) 推荐(0)
摘要:1. capitalize(): 首字母大写,其余全部小写 2. upper() :全转换成大写 3. lower(): 全转换成小写 4. title() :标题首字大写,如 "i love python".title() 输出为:"I love python" 阅读全文
posted @ 2017-12-13 21:48 西瓜刀刀刀 阅读(4170) 评论(0) 推荐(0)
摘要:字符串连接 方法1: 用字符串的join方法 方法2: 用字符串的替换占位符替换 字符串截取 我们可以通过索引来提取想要获取的字符,可以把python的字符串也做为字符串的列表就更好理解python的字串列表有2种取值顺序1是从左到右索引默认0开始的,最大范围是字符串长度少1s = 'ilovepy 阅读全文
posted @ 2017-12-12 22:28 西瓜刀刀刀 阅读(350) 评论(0) 推荐(0)
摘要:Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1. For 阅读全文
posted @ 2017-12-12 22:17 西瓜刀刀刀 阅读(212) 评论(0) 推荐(0)
摘要:在写C++程序中,总会遇到要从一个字符串中查找一小段子字符串的情况,对于在C中,我们经常用到strstr()或者strchr()这两种方法。而对于C++的string,我们往往会用到find()。 C++:#inlcude<string>C: #include<string.h>find():在一个 阅读全文
posted @ 2017-12-12 22:08 西瓜刀刀刀 阅读(12110) 评论(0) 推荐(1)
摘要:Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the or 阅读全文
posted @ 2017-12-12 21:25 西瓜刀刀刀 阅读(146) 评论(0) 推荐(0)
摘要:(1)代码: 阅读全文
posted @ 2017-12-11 22:38 西瓜刀刀刀 阅读(83) 评论(0) 推荐(0)
摘要:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, 阅读全文
posted @ 2017-12-11 22:22 西瓜刀刀刀 阅读(108) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2, 阅读全文
posted @ 2017-12-07 10:41 西瓜刀刀刀 阅读(143) 评论(0) 推荐(0)
摘要:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: You 阅读全文
posted @ 2017-12-07 10:21 西瓜刀刀刀 阅读(136) 评论(0) 推荐(0)
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted f 阅读全文
posted @ 2017-12-06 22:27 西瓜刀刀刀 阅读(143) 评论(0) 推荐(0)
摘要:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 给定一个m × n矩阵,如果一个元素为0,则将其整个行和列设置为0。 (1)思想1:用两个一维数组:flag_r 阅读全文
posted @ 2017-12-06 22:09 西瓜刀刀刀 阅读(122) 评论(0) 推荐(0)
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Write 阅读全文
posted @ 2017-12-05 15:50 西瓜刀刀刀 阅读(167) 评论(0) 推荐(0)
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You a 阅读全文
posted @ 2017-12-05 15:36 西瓜刀刀刀 阅读(113) 评论(0) 推荐(0)