摘要:
共有三种思路。 哈希表。 将较小的那个数组中的所有元素存在哈希表中。然后依次验证另一个数组中的数字是否有出现过。时间复杂度O(m + n),空间复杂度O(min(m, n)) 二分搜索法 将较小的那个数组中的每一个元素,都用二分搜索的方法在较大数组中验证是否出现过。当两个数组大小相差很大时,这种方法 阅读全文
摘要:
You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路:将这个矩阵沿左对角线(从左上角到... 阅读全文
摘要:
Given a set of distinct integers,nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not... 阅读全文
摘要:
Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文
摘要:
Given an array of strings, group anagrams together.For example, given:["eat", "tea", "tan", "ate", "nat", "bat"],Return:[ ["ate", "eat","tea"], ["na... 阅读全文
摘要:
Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume... 阅读全文
摘要:
Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:构建一个大小为K的小顶堆。每次从堆顶取走一个元素后,都将这个元素所属的链表中下一个元素加入堆中。若没有... 阅读全文
摘要:
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n... 阅读全文
摘要:
Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文
摘要:
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.The input string does not contain lead... 阅读全文