随笔分类 -  Algorithm

摘要:方法 时间复杂度 空间复杂度 Stable 冒泡排序(Bubble Sort) O(n) — O(n^2) O(1) yes 选择排序(Selection Sort) O(n^2) — O(n^2) O(1) no 插入排序(Insertion Sort) O(n) — O(n^2) O(1) ye 阅读全文
posted @ 2016-04-02 12:41 Joyce-Lee 阅读(309) 评论(0) 推荐(0)
摘要:http://www.geeksforgeeks.org/rearrange-a-string-so-that-all-same-characters-become-at-least-d-distance-away/ Given a string and a positive integer d. 阅读全文
posted @ 2016-04-02 11:53 Joyce-Lee 阅读(506) 评论(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 i 阅读全文
posted @ 2016-04-01 12:18 Joyce-Lee 阅读(196) 评论(0) 推荐(0)
摘要:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's 阅读全文
posted @ 2016-04-01 11:45 Joyce-Lee 阅读(504) 评论(0) 推荐(0)
摘要: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 floati 阅读全文
posted @ 2016-03-31 12:35 Joyce-Lee 阅读(454) 评论(0) 推荐(0)
摘要:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c 阅读全文
posted @ 2016-03-31 12:24 Joyce-Lee 阅读(167) 评论(0) 推荐(0)
摘要:An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black pixels are connected, i.e., there is only one bla 阅读全文
posted @ 2016-03-31 12:13 Joyce-Lee 阅读(162) 评论(0) 推荐(0)
摘要:A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand operation which turns the water at position (row, col) 阅读全文
posted @ 2016-03-25 12:08 Joyce-Lee 阅读(323) 评论(0) 推荐(0)
摘要: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 check whether these edges mak 阅读全文
posted @ 2016-03-23 12:19 Joyce-Lee 阅读(238) 评论(0) 推荐(0)
摘要: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 adjacen 阅读全文
posted @ 2016-03-15 13:11 Joyce-Lee 阅读(188) 评论(0) 推荐(0)
摘要:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded 阅读全文
posted @ 2016-03-15 13:02 Joyce-Lee 阅读(174) 评论(0) 推荐(0)
摘要: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 h 阅读全文
posted @ 2016-03-14 05:45 Joyce-Lee 阅读(191) 评论(0) 推荐(0)
摘要:You are given a m x n 2D grid initialized with these three possible values. Fill each empty room with the distance to its nearest gate. If it is impos 阅读全文
posted @ 2016-03-14 05:22 Joyce-Lee 阅读(253) 评论(0) 推荐(0)
摘要:You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You can only move up, down, left and right. 阅读全文
posted @ 2016-03-14 05:15 Joyce-Lee 阅读(281) 评论(0) 推荐(0)
摘要:1.Given an array of integers, find a contiguous subarray which has the largest sum.hint: Go through the array with 2 variable -- cur and count. cur i... 阅读全文
posted @ 2015-05-21 15:27 Joyce-Lee 阅读(265) 评论(0) 推荐(0)
摘要:Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called 'serialization' and reading back f... 阅读全文
posted @ 2015-05-20 15:03 Joyce-Lee 阅读(190) 评论(0) 推荐(0)
摘要:Given a BST, find 2 nodes in it which sum to a given targethint:Inorder traversal + BST + 2 SUM* Time : O(N)* Space: O(lgN) 1 class TreeNode0 { 2 ... 阅读全文
posted @ 2015-05-20 12:01 Joyce-Lee 阅读(331) 评论(0) 推荐(0)
摘要:Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 ... 阅读全文
posted @ 2015-05-20 07:08 Joyce-Lee 阅读(258) 评论(0) 推荐(0)
摘要:Given one point P0 on a 2-dimension space.There are n other points on the same space.Try to find K points which are most closed to P0.hint: Part ofQu... 阅读全文
posted @ 2015-05-20 07:01 Joyce-Lee 阅读(258) 评论(0) 推荐(0)
摘要:Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) and an query list. For each query, give you ... 阅读全文
posted @ 2015-05-20 06:51 Joyce-Lee 阅读(328) 评论(0) 推荐(0)