04 2015 档案
Lintcode: Singleton && Summary: Synchronization and OOD
摘要:Singleton is a most widely used design pattern. If a class has and only has one instance at every moment, we call this design as singleton. For exampl...
阅读全文
Lintcode: Topological Sorting
摘要:这道题参考了网上一些很好的思路: method1: Record the pre nodes of every node, then find out a node without pre node in each iteration and delete this node from unvisi
阅读全文
Lintcode: Rotate String
摘要:Given a string and an offset, rotate string by offset. (rotate from left to right)ExampleGiven "abcdefg"for offset=0, return "abcdefg"for offset=1, re...
阅读全文
Lintcode: Two Strings Are Anagrams
摘要:Write a method anagram(s,t) to decide if two strings are anagrams or not.ExampleGiven s="abcd", t="dcab", return trueO(N)time, O(1) space 1 public cla...
阅读全文
Leetcode: House Robber
摘要:This particular problem and most of others can be approached using the following sequence: https://leetcode.com/problems/house-robber/discuss/156523/F
阅读全文
Leetcode: Binary Tree Right Side View
摘要:这道题就是BT的Level Order Traversal,每次要换一层的时候,记录当前节点 注意,每次都是先添加右边child,所以是i==0的时候add
阅读全文
Leetcode: Number of Islands
摘要:DFS的Flood Fill方法, 不使用额外visited数组,但是用‘1’变成‘2’表示visited的方法 复杂度 时间 O(NM) 空间 O(max(N,M)) 递归栈空间 Union Find: (Quick Union) follow up是找最大岛的面积,想法是设置两个全局变量 max
阅读全文
Lintcode: Subarray Sum
摘要:Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the l...
阅读全文
Lintcode: Sort Letters by Case
摘要:Given a string which contains only letters. Sort it by lower case first and upper case second.NoteIt's not necessary to keep the original order of low...
阅读全文
Lintcode: Sort Colors II
摘要:Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors ...
阅读全文
Lintcode: Single Number III
摘要:Given 2*n + 2 numbers, every numbers occurs twice except two, find them.ExampleGiven [1,2,2,3,4,4,5,3] return 1 and 5ChallengeO(n) time, O(1) extra sp...
阅读全文
Lintcode: Search Range in Binary Search Tree
摘要:Given two values k1 and k2 (where k1 k1, 如果否,则不需要继续向左递归;右子树的处理方法类似第一次做法,把result数组作为return type,不好,消耗额外空间 1 public class Solution { 2 /** 3 *...
阅读全文
Lintcode: Binary Tree Serialization (Serialization and Deserialization Of Binary Tree)
摘要: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...
阅读全文
Lintcode: Search a 2D matrix II
摘要:Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence of it.This matrix has the following properties: * ...
阅读全文
Lintcode: Rehashing
摘要:The size of the hash table is not determinate at the very beginning. If the total size of keys is too large (e.g. size >= capacity / 10), we should do...
阅读全文
Lintcode: Recover Rotated Sorted Array
摘要:Given a rotated sorted array, recover it to sorted array in-place.Example[4, 5, 1, 2, 3] -> [1, 2, 3, 4, 5]ChallengeIn-place, O(1) extra space and O(n...
阅读全文
Lintcode: Product of Array Exclude Itself
摘要:Given an integers array A.Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B without divide operation.ExampleFor A=[1, 2, 3], B is...
阅读全文
Lintcode: Previous Permuation
摘要:Given a list of integers, which denote a permutation.Find the previous permutation in ascending order.NoteThe list may contains duplicate integers.Exa...
阅读全文
Lintcode: Partition Array
摘要:Given an array "nums" of integers and an int "k", Partition the array (i.e move the elements in "nums") such that, * All elements = k are moved to ...
阅读全文
Lintcode: O(1) Check Power of 2
摘要:Using O(1) time to check whether an integer n is a power of 2.ExampleFor n=4, return trueFor n=5, return falseChallengeO(1) timeTags Expand 这道题考察bit m...
阅读全文
Lintcode: Minimum Adjustment Cost
摘要:1 Given an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.2 3 If the ...
阅读全文
Lintcode: Nth to Last Node in List
摘要:Find the nth to last element of a singly linked list. The minimum number of nodes in list is n.ExampleGiven a List 3->2->1->5->null and n = 2, return...
阅读全文
Summary: Trie Data Structure
摘要:Implement a Trie Data Structure, and search() & insert() function: we need to implement both Class Trie and Class TrieNode Class Trie: Class TrieNode:
阅读全文