![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
文章平均质量分 73
加藤蜀黍
攻城狮,程序猿
展开
-
Leetcode 刷题 - 332 - Reconstruct Itinerary
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus原创 2016-02-25 08:50:38 · 808 阅读 · 0 评论 -
Leetcode 刷题 - 199 - Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1原创 2016-02-09 14:20:12 · 165 阅读 · 0 评论 -
Leetcode 刷题 - 288 - Unique Word Abbreviation
An abbreviation of a word follows the form . Below are some examples of word abbreviations:a) it --> it (no abbreviation) 1b) d|o|g --> d1g原创 2016-02-06 09:40:48 · 197 阅读 · 0 评论 -
Leetcode 刷题 - 303 - Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan原创 2016-02-06 05:44:58 · 159 阅读 · 0 评论 -
Leetcode 刷题 - 276 - Paint Fence
There is a fence with n posts, each post can be painted with one of the k colors.You have to paint all the posts such that no more than two adjacent fence posts have the same color. Return the原创 2016-01-08 15:31:20 · 278 阅读 · 0 评论 -
Leetcode 刷题 - 270 - Closest Binary Search Tree Value
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note:Given target value is a floating point.You are guaranteed to have only o原创 2016-01-08 07:12:32 · 233 阅读 · 0 评论 -
Leetcode 刷题 - 246 - Strobogrammatic Number
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to determine if a number is strobogrammatic. The number is represented as原创 2016-01-08 05:09:06 · 210 阅读 · 0 评论 -
Leetcode 刷题 - 325 - Maximum Size Subarray Sum Equals k
Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.Example 1:Given nums = [1, -1, 5, -2, 3], k = 3,return原创 2016-01-08 03:52:17 · 2034 阅读 · 0 评论 -
Leetcode 刷题 - 157 - Read N Characters Given Read4
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the原创 2016-01-17 19:01:59 · 150 阅读 · 0 评论 -
Leetcode 刷题 - 200 - Number of Islands (*)
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu原创 2016-01-25 14:52:09 · 194 阅读 · 0 评论 -
Leetcode 刷题 - 252 - Meeting Rooms
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.For example,Given [[0, 30],[5, 10],[原创 2016-01-07 17:18:22 · 230 阅读 · 0 评论 -
Leetcode 刷题 - 243 - Shortest Word Distance
Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.For example,Assume that words = ["practice", "makes", "perfect", "coding", "原创 2016-01-07 03:26:54 · 279 阅读 · 0 评论 -
Leetcode 刷题 - 266 - Palindrome Permutation
Given a string, determine if a permutation of the string could form a palindrome.For example,"code" -> False, "aab" -> True, "carerac" -> True.根据题意,判断一个string是否仅需要调换一下字母的顺序就能得到回文字符串。原创 2016-01-06 15:03:54 · 314 阅读 · 0 评论 -
Leetcode 刷题 - 293 - Flip Game
You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive "++" into "--". Th原创 2016-01-06 14:38:40 · 424 阅读 · 0 评论 -
Leetcode 刷题 - 260 - Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given原创 2016-01-22 04:38:12 · 190 阅读 · 0 评论 -
Leetcode 刷题 - 280 - Wiggle Sort
Given an unsorted array nums, reorder it in-place such that nums[0] = nums[2] .For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4].根据题意,不去看给出的例子,那原创 2016-01-20 14:42:58 · 166 阅读 · 0 评论 -
Leetcode 刷题 - 328 - Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in原创 2016-01-18 16:17:55 · 314 阅读 · 0 评论 -
Python interview - Any, All, Cmp, Dict, Enumerate
Python interview - Any, All, Cmp, Dict, Enumerate原创 2016-02-09 18:18:02 · 263 阅读 · 0 评论 -
Leetcode 刷题 - 167 - Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two number原创 2016-01-22 08:35:19 · 176 阅读 · 0 评论 -
Leetcode 刷题 - 323 - Number of Connected Components in an Undirected Graph
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to find the number of connected components in an undirected graph.Example 1:原创 2016-02-23 16:02:36 · 723 阅读 · 0 评论 -
Leetcode 刷题 - 294 - Flip Game II
You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive "++" into "--". Th原创 2016-02-05 03:18:27 · 364 阅读 · 0 评论 -
Leetcode 刷题 - 296 - Best Meeting Point
A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1 marks the home of someone in the group. The distance is calcu原创 2016-02-17 05:59:59 · 857 阅读 · 0 评论 -
Leetcode 刷题 - 186 - Reverse Words in a String II
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.The input string does not contain leading or trailing spaces and the words are alway原创 2016-01-25 16:34:29 · 391 阅读 · 0 评论 -
Leetcode 刷题 - 311 - Sparse Matrix Multiplication
Given two sparse matrices A and B, return the result of AB.You may assume that A's column number is equal to B's row number.Example:A = [ [ 1, 0, 0], [-1, 0, 3]]B = [ [ 7, 0, 0 ],原创 2016-02-13 09:34:29 · 517 阅读 · 0 评论 -
Leetcode 刷题 - 238 - 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原创 2016-02-13 08:24:19 · 141 阅读 · 0 评论 -
Leetcode 刷题 - 238 - 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 O2016-02-13 08:14:03 · 70 阅读 · 0 评论 -
Leetcode 刷题 - 233 - Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the followin原创 2016-02-12 09:50:42 · 187 阅读 · 0 评论 -
Leetcode 刷题 - 170 - Two Sum III - Data structure design
Design and implement a TwoSum class. It should support the following operations: add and find.add - Add the number to an internal data structure.find - Find if there exists any pair of numbers w原创 2016-01-13 08:11:22 · 173 阅读 · 0 评论 -
Leetcode 刷题 - 205 - Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot原创 2016-01-13 06:15:46 · 192 阅读 · 0 评论 -
Leetcode 刷题 - 249 - Group Shifted Strings
Given a string, we can "shift" each of its letter to its successive letter, for example: "abc" -> "bcd". We can keep "shifting" which forms the sequence:"abc" -> "bcd" -> ... -> "xyz"Given a l原创 2016-01-13 03:09:15 · 249 阅读 · 0 评论 -
Leetcode 刷题 - 268 - Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm shoul原创 2016-02-10 15:03:11 · 177 阅读 · 0 评论 -
Leetcode 刷题 - 245 - Shortest Word Distance III
This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as word2.Given a list of words and two words word1 and word2, return the shortest distance betwe原创 2016-02-10 14:17:43 · 227 阅读 · 0 评论 -
Leetcode 刷题 - 244 - Shortest Word Distance II
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameters. How would yo原创 2016-02-10 13:55:49 · 260 阅读 · 0 评论 -
Leetcode 刷题 - 299 - Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t原创 2016-02-10 08:04:43 · 252 阅读 · 0 评论 -
Leetcode 刷题 - 225 - Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet原创 2016-02-10 06:37:42 · 176 阅读 · 0 评论 -
Python interview - Python 垃圾处理机制
面试的时候问到了Python的GC,垃圾处理机制是怎么样的。 没仔细研究就直接进了一个大坑。现在总结网上大牛们博客来自己写一个总结。在国内博客上,看到的关键词都是:引用计数,标记引用,分代回收。对应的国外帖子中就是:reference counting, mark and sweep, 分代回收没有固定的词,但是翻译成generation collection还是不错的,个人觉得gen原创 2015-12-31 14:01:14 · 319 阅读 · 0 评论 -
Python Interview - __init__.py
Python & Django Framework 相对于J2EE的MVC来说,是MTV架构。 Models,V原创 2014-10-09 02:32:21 · 366 阅读 · 0 评论 -
Python interview - text to JSON & zip & with statement
自己写的小例子,就是把本地的txt文件转换为JSON格式输出。data source简单的1-10存一个文件, A-J 存一个文件import jsonbook = 'C:\Python27\\book.txt'date = 'C:\Python27\date.txt'book_list = []date_list = []with open(book)原创 2014-10-29 07:44:32 · 744 阅读 · 1 评论 -
Python interview - mutable & immutable
python中的数据类型有分可变类型mutable原创 2014-10-08 16:01:11 · 364 阅读 · 0 评论 -
Python interview - reduce & map & filter
Python有很多有用有趣的内置函数,比如reduce,map,filter,lambda,zip等。已经写过了lambda和zip相关的博客。继续写关于reduce,map,filter。Map首先用help方法看一下map的具体用法。help(map)# resultHelp on built-in function map in module __buil原创 2014-11-15 05:33:45 · 347 阅读 · 0 评论