- 博客(52)
- 收藏
- 关注
原创 for循环打印字典
代码实现bat = {'a': 'alibaba', 'b': 'baidu', 't': 'tencent'}for value in bat.values(): print valuefor key in bat: print keyfor k,v in bat.items(): print k, '>', v
2016-07-14 19:13:29
1174
原创 查看字典元素
代码实现bat = {'a': 'alibaba', 'b': 'baidu', 't': 'tencent'}print bat.keys()#取键名print bat.values()#取键值print bat.items()#取键值对
2016-07-14 19:08:41
479
原创 交叉排序
题目描述输入一行 k 个用空格分隔开的整数,依次为 n1, n2 … nk。请将所有下标不能被 3 但可以被 2 整除的数在这些数字原有的位置上进行升序排列,此外,将余下下标能被 3 整除的数在这些数字原有的位置上进行降序排列。
2016-07-14 18:04:36
332
原创 Python的find()
find()函数find()函数会在原字符串中查找参数传入的子字符串,如果没有找到请求的字符串就会返回-1,否则返回找到的子字符串的第一个字符在原字符串中的索引位置。
2016-07-12 17:30:32
787
原创 用Python求A+B+C
问题描述输入为一行,包括用空格分隔的三个整数,分别为 A、B、C(数据范围均在 -40 ~ 40 之间)。输出为一行,为“A+B+C”的计算结果。代码实现sum = 0
2016-07-12 16:16:38
5569
原创 用Python实现斐波拉契数列
问题描述著名的斐波拉契数列(Fibonacci),除第一个和第二个数外,任意一个数都可由前两个数相加得到:1, 1, 2, 3, 5, 8, 13, 21, 34, …
2016-07-08 15:08:51
1812
原创 用Python递归实现汉诺塔问题
问题描述汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具。大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64片黄金圆盘。大梵天命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上。并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一次只能移动一个圆盘。
2016-07-07 20:24:38
2633
原创 【leetcode】Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
2016-06-08 12:34:02
213
原创 【leetcode】Power of Three
Given an integer, write a function to determine if it is a power of three.
2016-06-02 13:46:41
217
原创 【leetcode】Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.
2016-06-01 19:40:06
202
原创 【leetcode】Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
2016-06-01 16:01:28
204
原创 【leetcode】Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.
2016-06-01 15:36:24
206
原创 【leetcode】Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.
2016-06-01 10:32:56
201
原创 【leetcode】Move Zeroes
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.
2016-05-31 20:23:29
218
原创 【leetcode】Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.
2016-05-31 15:53:09
255
原创 【Leetcode】Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones.
2016-05-25 13:28:59
187
原创 【Leetcode】Number of 1 Bits(easy)
QuestionWrite a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).
2016-05-19 20:07:37
185
原创 【Leetcode】Add Digits(easy)
QuestionGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.
2016-05-19 19:19:07
176
原创 【Leetcode】Reverse String(easy)
QuestionWrite a function that takes a string as input and returns the string reversed.
2016-05-19 15:27:35
197
原创 【Leetcode】Two sum(easy)
QuestionGiven an array of integers, return indices of the two numbers such that they add up to a specific target.
2016-05-18 19:34:10
264
原创 合并表记录(map)
题目描述数据表记录包含表索引和数值,请对表索引相同的记录进行合并,即将相同索引的数值进行求和运算,输出按照key值升序进行输出。
2016-04-28 16:13:20
380
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人