随笔分类 - API Design
1
摘要:[抄题]: Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. The robot cleaner with 4 given APIs can move f
阅读全文
摘要:[抄题]: Given an array w of positive integers, where w[i] describes the weight of index i, write a function pickIndex which randomly picks an index in p
阅读全文
摘要:[抄题]: Design a Tic-tac-toe game that is played between two players on a n x n grid. You may assume the following rules: Example: [暴力解法]: 时间分析: 空间分析: [
阅读全文
摘要:[抄题]: Given two 1d vectors, implement an iterator to return their elements alternately. Example: Follow up: What if you are given k 1d vectors? How we
阅读全文
摘要:[抄题]: Implement an iterator to flatten a 2d vector. Example: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: j必须非空且有下才行j != null &&
阅读全文
摘要:[抄题]: Design a max stack that supports push, pop, top, peekMax and popMax. Example 1: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]
阅读全文
摘要:[抄题]: 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 lis
阅读全文
摘要:[抄题]: Design a class which receives a list of words in the constructor, and implements a method that takes two words word1 and word2 and return the sh
阅读全文
摘要:[抄题]: Shuffle a set of numbers without duplicates. Example: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [英文数据结构或算法,为什么不用
阅读全文
摘要:[抄题]: Given many words, words[i] has weight i. Design a class WordFilter that supports one function, WordFilter.f(String prefix, String suffix). It wi
阅读全文
摘要:[抄题]: Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target nu
阅读全文
摘要:[抄题]: Design a data structure that supports all following operations in average O(1) time. Note: Duplicate elements are allowed. Example: [暴力解法]: 时间分析
阅读全文
摘要:[抄题]: Design a data structure that supports all following operations in average O(1) time. Example: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [
阅读全文
摘要:[抄题]: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such a
阅读全文
摘要:[抄题]: Design a logger system that receive stream of messages along with its timestamps, each message should be printed if and only if it is not printe
阅读全文
摘要:[抄题]: Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. For example, [暴力解法]: 时间分析: 空间分
阅读全文
摘要:[抄题]: 设计一个包含下面两个操作的数据结构:addWord(word), search(word) addWord(word)会在数据结构中添加一个单词。而search(word)则支持普通的单词查询或是只包含.和a-z的简易正则表达式的查询。 一个 . 可以代表一个任何的字母。 [暴力解法]:
阅读全文
摘要:[抄题]: Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs are consist of lowercase letters a-z. [暴力解法]:
阅读全文
摘要:[抄题]: 一个单词的缩写根据以下的形式。下面是一些缩写的例子 假设你有一个字典和给你一个单词,判断这个单词的缩写在字典中是否是唯一的。当字典中的其他单词的缩写均与它不同的时候, 这个单词的缩写是唯一的. [暴力解法]: 1把缩写全部存一遍,再一个个搜索是否为重复,不重复unique 时间分析: 空
阅读全文
摘要:[抄题]: 实现一个带有取最小值min方法的栈,min方法将返回当前栈中的最小值。 你实现的栈将支持push,pop 和 min 操作,所有操作要求都在O(1)时间内完成。 [思维问题]: 想不到,脑洞不够大 [一句话思路]: 用一个minstack来辅助实现 [输入量]:空: 正常情况:特大:特小
阅读全文
1

浙公网安备 33010602011771号