上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 18 下一页
摘要: 共有三种思路。 哈希表。 将较小的那个数组中的所有元素存在哈希表中。然后依次验证另一个数组中的数字是否有出现过。时间复杂度O(m + n),空间复杂度O(min(m, n)) 二分搜索法 将较小的那个数组中的每一个元素,都用二分搜索的方法在较大数组中验证是否出现过。当两个数组大小相差很大时,这种方法 阅读全文
posted @ 2016-01-28 07:59 fenshen371 阅读(122) 评论(0) 推荐(0) 编辑
摘要: You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路:将这个矩阵沿左对角线(从左上角到... 阅读全文
posted @ 2016-01-27 13:07 fenshen371 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2016-01-27 12:48 fenshen371 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文
posted @ 2016-01-27 12:18 fenshen371 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Given an array of strings, group anagrams together.For example, given:["eat", "tea", "tan", "ate", "nat", "bat"],Return:[ ["ate", "eat","tea"], ["na... 阅读全文
posted @ 2016-01-27 12:08 fenshen371 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume... 阅读全文
posted @ 2016-01-27 09:18 fenshen371 阅读(129) 评论(0) 推荐(0) 编辑
摘要: Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:构建一个大小为K的小顶堆。每次从堆顶取走一个元素后,都将这个元素所属的链表中下一个元素加入堆中。若没有... 阅读全文
posted @ 2016-01-27 08:47 fenshen371 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2016-01-27 06:36 fenshen371 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2016-01-27 06:00 fenshen371 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2016-01-26 14:28 fenshen371 阅读(139) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 18 下一页