- 博客(90)
- 收藏
- 关注
原创 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 804
原创 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 718
原创 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 846
原创 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 511
原创 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 138
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:14:03 67
原创 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 185
原创 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 176
原创 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 225
原创 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 256
原创 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 242
原创 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 173
原创 Python interview - Any, All, Cmp, Dict, Enumerate
Python interview - Any, All, Cmp, Dict, Enumerate
2016-02-09 18:18:02 258
原创 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 163
原创 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 193
原创 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 157
原创 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 362
原创 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 383
原创 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 190
原创 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 175
原创 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 186
原创 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 164
原创 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 311
原创 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 148
原创 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 170
原创 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 190
原创 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 245
原创 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 271
原创 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 220
原创 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 208
原创 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 2028
原创 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 225
原创 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 255
原创 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 310
原创 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 415
原创 Scala interview - val & var
从0开始学Scala,因为工作需要所以就都是直接上手看例子写代码。现在开始慢慢回补漏洞。Scala 有两种变量: val 和 var。 val相当于Java中得final变量,一旦初始化了之后,就不能在赋值。对应的,var就是Java中的非final变量,可以在生命周期中被多次赋值。对应python来理解,val就是immutable,var就是mutable。举例说明:
2016-01-04 09:50:20 192
原创 Scala Assignment - week 1
Scala Assignment 1package recfunimport common._import scala.collection.immutable.Stackobject Main { def main(args: Array[String]) { println("Pascal's Triangle") for (row <- 0 t
2016-01-01 14:40:18 170
原创 Python interview - Python 垃圾处理机制
面试的时候问到了Python的GC,垃圾处理机制是怎么样的。 没仔细研究就直接进了一个大坑。现在总结网上大牛们博客来自己写一个总结。在国内博客上,看到的关键词都是:引用计数,标记引用,分代回收。对应的国外帖子中就是:reference counting, mark and sweep, 分代回收没有固定的词,但是翻译成generation collection还是不错的,个人觉得gen
2015-12-31 14:01:14 315
原创 Python interview - sys & os
工作中碰到需要很多的VM,以及不同user对应不同的python环境。debug的时候碰到问题:这个包明明在可见的路径下,并且有__init__.py,为什么python看不到(不能导入)。用Python的都应该很熟悉的,能够导入的情况有大概三种:1. .py 文件在当前目录下2. .py 文件的path被添加到了sys.path的list里面3. .py 文件所在的p
2015-12-30 15:44:39 230
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人