- 博客(155)
- 收藏
- 关注
原创 CodingTMD’s Reading List
Following reading list is selected from the papers I had read in the past 3 years. It will help you to gain a basic knowledge of what happened in current industry and bring you a little sense about ho
2016-01-12 11:13:00
800
原创 [LeetCode] Evaluate Reverse Polish Notation, Solution
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2", "1", "+", "3", "
2016-01-12 11:12:57
389
原创 [LeetCode] Clone Graph, Solution
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ’s undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each node,
2016-01-12 11:12:55
390
原创 [LeetCode] Sort List, Solution
Sort a linked list in O(n log n) time using constant space complexity.[Thoughts]O(nlgn)的排序算法没几个,无非就是quick sort, heap sort和merge sort. 对于链表排序来说,难点之一就是如何O(1)定位节点。如果是数组,那么可以通过下标直接找到节点,但是对于链表,很明显没有下标这个东西
2016-01-12 11:12:53
389
原创 [LeetCode] Max Points on a Line, Solution
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.[Thoughts]任意一条直线都可以表述为y = ax + b假设,有两个点(x1,y1), (x2,y2),如果他们都在这条直线上则有y1 = kx1 +by2 = kx2 +b由此可以得到关系,k
2016-01-12 11:12:51
289
原创 [LeetCode] LRU Cache, Solution
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) – Get the value (will always be positive) of the key if the
2016-01-12 11:12:49
310
原创 [LeetCode] Binary Tree Preorder Traversal, Solution
Given a binary tree, return the preorder traversal of its nodes’ values. For example:Given binary tree {1,#,2,3}, 1 2 / 3return [1,2,3].Note: Recursive solution is trivial, could you
2016-01-12 11:12:46
260
原创 [LeetCode] Reorder List, Solution
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes’ values.For example,Given {1,2,3,4}, reorder it to {1,4,2,3}.
2016-01-12 11:12:44
301
原创 [LeetCode] Linked List Cycle II, Solution
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?[Thoughts]首先,比较直观的是,先使用Linked List Cycle I的办法,判断是
2016-01-12 11:12:42
300
原创 [LeetCode] Linked List Cycle, Solution
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? [Thoughts]设定两个指针,一个每次走一步,一个每次走两步,如果链表上有环的话,两个指针必定能相遇。否则,则无环[Code]Code highlighting p
2016-01-12 11:12:06
252
原创 [LeetCode] WordBreak II, Solution
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "catsandd
2016-01-12 11:12:03
243
原创 [LeetCode] Word Break, Solution
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet", "code
2016-01-12 11:12:01
268
原创 [LeetCode] Copy List with Random Pointer, Solution
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list. [Thoughts]如图分三步:1. 插入拷贝节点2. 复制r
2016-01-12 11:11:59
315
原创 [LeetCode] Single Number II, Solution
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ex
2016-01-12 11:11:57
316
原创 [LeetCode] Single Number, Solution
Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra m
2016-01-12 11:11:55
273
原创 [LeetCode] Candy, Solution
There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one ca
2016-01-12 11:11:52
262
原创 [LeetCode] Gas Station, Solution
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its n
2016-01-12 11:11:50
235
原创 [Microsoft] string permutation with upcase and lowcase
Give a string, which only contains a-z. List all the permutation of upcase and lowcase. For example, str = “ab”, the output should be “ab”, “aB”, “Ab”, “AB” for str = “abc”, the output should be “abc
2016-01-12 11:11:48
292
原创 [TopCoder] SRM 586 DIV 2, 500p, 1000p, Solution
Problem Statement F is a function that is defined on all real numbers from the closed interval [1,N]. You are given a vector Y with N elements. For each i (1 Y[i-1]. Additionally,
2016-01-12 11:11:46
407
原创 [TopCoder] SRM 587 DIV 2, 250p, 500p, 1000p, Solution
Problem Statement 250P You are given two strings: init and goal. Both init and goal contain lowercase letters only. Additionally, init does not contain the
2016-01-12 11:11:42
530
原创 [TopCoder] SRM 581 DIV 2, 250p, 500p, 1000p, Solution
250P Problem Statement Manao has N cards arranged in a sequence. He numbered them from left to right with numbers from 0 to N-1. Each card is colored
2016-01-12 11:11:40
521
原创 [TopCoder] SRM580, DIV1, 600p, Solution
Problem Statement A group of freshman rabbits has recently joined the Eel club. No two of the rabbits knew each other. Yesterday, each of the rabbits
2016-01-12 11:11:38
377
原创 [TopCoder] SRM 580 DIV 2, 250p, 500p, 1000p, Solution
250 points Problem Statement A group of freshman rabbits has recently joined the Eel club. No two of the rabbits knew each other. Today, each o
2016-01-12 11:11:36
377
原创 [TopCoder] SRM 579 DIV 2, Marble Positioning, Solution
Problem Statement NOTE: This problem statement contains images that may not display properly if viewed outside of the applet.Everybody loves geometry
2016-01-12 11:11:34
273
原创 [TopCoder] SRM 578 DIV 2, Goose In Zoo, Solution
Problem Statement Crow Keith is looking at the goose cage in the zoo. The bottom of the cage is divided into a grid of square cells. There are some bi
2016-01-12 11:11:31
369
原创 Algorithm and Data Structure Review
常用总结。1、常见数据结构线性: 数组:Merge Sorted Array 链表:Merge k Sorted Lists,Partition List 队列, 堆栈, 块状数组(数组+链表), hash表, 双端队列, 位图(bitmap)树: 二叉
2016-01-12 11:11:29
457
原创 [LeetCode] Permutation Sequence, Solution
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""312""
2016-01-12 11:11:27
194
原创 [LeetCode] Spiral Matrix II, Solution
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]
2016-01-12 11:11:25
169
原创 [LeetCode] Merge Intervals, Solution
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].» Solve this problem[Thoughts]复用一下Insert Intervals的解法即可,htt
2016-01-12 11:11:23
314
原创 [LeetCode] Regular Expression Matching, Solution
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string
2016-01-12 11:11:19
198
原创 [LeetCode] Path Sum, Solution
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum = 2
2016-01-12 11:11:17
226
原创 [Interview] Serialize and De-serialize a tree
A very frequent interview question. Suppose you have a tree, how could you serialize it to file and revert it back?for example, 1
2016-01-12 11:11:14
162
原创 [LeetCode] Convert Sorted Array to Binary Search Tree, Solution
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.» Solve this problem[Thoughts][Code]1: TreeNode *sortedArrayToBST(vector &num) { 2:
2016-01-12 11:11:12
226
原创 [LeetCode] Same Tree, Solution
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.» Solve this pro
2016-01-12 11:11:10
204
原创 [LeetCode] Unique Binary Search Trees II, Solution
Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example,Given n = 3, your program should return all 5 unique BST’s shown below. 1 3 3
2016-01-12 11:11:08
171
原创 [LeetCode] Unique Binary Search Trees, Solution
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example,Given n = 3, there are a total of 5 unique BST’s. 1 3 3 2 1 /
2016-01-12 11:11:06
149
原创 [LeetCode] Remove Duplicates from Sorted List II, Solution
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1->2->
2016-01-12 11:11:03
158
原创 [LeetCode] Search a 2D Matrix, Solution
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 from left to right.The first integer of each row
2016-01-12 11:11:01
157
原创 [LeetCode] Merge Two Sorted Lists, Solution
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.» Solve this problem[Thoughts]简单的实现,也没什么可说的。[Code]1:
2016-01-12 11:10:59
159
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人