随笔分类 - Data Structure
摘要:Design and implement an iterator to flatten a 2d vector. It should support the following operations: next and hasNext. Example: Vector2D iterator = ne
阅读全文
摘要:Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list -- whose elements may also be integ
阅读全文
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov
阅读全文
摘要:Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two
阅读全文
摘要:Given two 1d vectors, implement an iterator to return their elements alternately. Example: Input: v1 = [1,2] v2 = [3,4,5,6] Output: [1,3,2,4,5,6] Expl
阅读全文
摘要:Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it e
阅读全文
摘要:Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer or a list -- wh
阅读全文
摘要:Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer or a list -- whose elements may also be intege
阅读全文
摘要:Design and implement an iterator to flatten a 2d vector. It should support the following operations: next and hasNext. Example: Vector2D iterator = ne
阅读全文
摘要:Implement the RandomizedSet class: bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, fal
阅读全文
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov
阅读全文
摘要:Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two
阅读全文
摘要:Given two 1d vectors, implement an iterator to return their elements alternately. Example: Input: v1 = [1,2] v2 = [3,4,5,6] Output: [1,3,2,4,5,6] Expl
阅读全文
摘要:Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it e
阅读全文
摘要:Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer or a list -- wh
阅读全文
摘要:Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list -- whose elements may also be integ
阅读全文
摘要:Design and implement an iterator to flatten a 2d vector. It should support the following operations: next and hasNext. Example:Vector2D iterator = new
阅读全文
摘要:Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list -- w
阅读全文
摘要:Implement an iterator to flatten a 2d vector. Example: Input: 2d vector = [ [1,2], [3], [4,5,6] ] Output: [1,2,3,4,5,6] Explanation: By calling next r
阅读全文
摘要:[抄题]: There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of t
阅读全文