随笔分类 - LintCode
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then l
阅读全文
摘要:Design a parking lot. see CC150 OO Design for details.1) n levels, each level has m rows of spots and each row has k spots.So each level has m x k spo
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head. Given a linked list, swap every two adjacent nodes and return its head. Exampl
阅读全文
摘要:Remove all elements from a linked list of integers that have value val. Remove all elements from a linked list of integers that have value val. Have y
阅读全文
摘要:Flatten a binary tree to a fake "linked list" in pre-order traversal. Here we use the right pointer in TreeNode as the next pointer in ListNode. Notic
阅读全文
摘要:Given an integer array, sort it in ascending order. Use quick sort, merge sort, heap sort or any O(nlogn) algorithm. Given an integer array, sort it i
阅读全文
摘要:Given an integer array, sort it in ascending order. Use selection sort, bubble sort, insertion sort or any O(n2) algorithm. Given an integer array, so
阅读全文
摘要:Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value.
阅读全文
摘要:Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. Th
阅读全文
摘要:Design a data structure that supports the following two operations: addWord(word) and search(word)search(word) can search a literal word or a regular
阅读全文
摘要: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 surrounde
阅读全文
摘要:Given two arrays, write a function to compute their intersection.Notice Each element in the result should appear as many times as it shows in both arr
阅读全文
摘要:Given two arrays, write a function to compute their intersection.Notice Each element in the result must be unique. The result can be in any order.Have
阅读全文
摘要:Given a binary tree, return all root-to-leaf paths.ExampleGiven the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:[ "1->2->5", "1->3"]
阅读全文
摘要:Write an algorithm to determine if a number is happy. A happy number is a number defined by the following process: Starting with any positive integer,
阅读全文
摘要:Factory is a design pattern in common usage. Please implement a ToyFactory which can generate proper toy based on the given type.ExampleToyFactory tf
阅读全文
摘要:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Notice You must
阅读全文
摘要:Factory is a design pattern in common usage. Implement a ShapeFactory that can generate correct shape. You can assume that we have only tree different
阅读全文
摘要:Implement a simple twitter. Support the following method: postTweet(user_id, tweet_text). Post a tweet.getTimeline(user_id). Get the given user's most
阅读全文
摘要:Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... Notice You may assume all input has valid answer. Example
阅读全文