随笔分类 -  Leetcode+题

上一页 1 2 3 4 5 6 ··· 9 下一页
摘要:Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two n 阅读全文
posted @ 2017-07-20 20:13 王大咩的图书馆 阅读(243) 评论(0) 推荐(0)
摘要:Given an index k, return the k th row of the Pascal's triangle. For example, given k = 3,Return[1,3,3,1]. Note: Could you optimize your algorithm to u 阅读全文
posted @ 2017-07-20 16:35 王大咩的图书馆 阅读(198) 评论(0) 推荐(0)
摘要:Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return 题意:给定行数构建帕斯卡三角。 思路:注意行数和该行中列数的关系,还有每行中非首尾元素时,该元素 阅读全文
posted @ 2017-07-20 15:40 王大咩的图书馆 阅读(139) 评论(0) 推荐(0)
摘要:Divide two integers without using multiplication, division and mod operator. 题意:两数相除不能用乘法、除、取余运算。 思路:直观的想法是相减,使用计算器p记下相减的次数n,这样时间复杂度为O(n)(n代表相减次数)。这是如 阅读全文
posted @ 2017-07-20 15:17 王大咩的图书馆 阅读(377) 评论(0) 推荐(0)
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example:Given"25525511135", return["255 阅读全文
posted @ 2017-07-19 18:59 王大咩的图书馆 阅读(412) 评论(0) 推荐(0)
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2]have the following unique per 阅读全文
posted @ 2017-07-19 16:30 王大咩的图书馆 阅读(218) 评论(0) 推荐(0)
摘要:Given a collection of numbers, return all possible permutations. For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3 阅读全文
posted @ 2017-07-19 15:59 王大咩的图书馆 阅读(149) 评论(0) 推荐(0)
摘要:Implement pow(x, n). 题意:计算x的次方 思路:这题的思路和sqrt的类似,向二分靠近。例如求4^5,我们可以这样求:res=4、4*4^4。就是将每次在res的基础上乘以x本身,换成,每次以x*=x的方式前行,这样时间复杂度为O(logn),代码如下: 把x的n次方划分成两个x 阅读全文
posted @ 2017-07-19 14:46 王大咩的图书馆 阅读(226) 评论(0) 推荐(0)
摘要:Implementint sqrt(int x). Compute and return the square root of x. 题意:求根号下x 的值 思路:使用二分搜索。先定义x平方根的取值区间,取值区间不同,在一些细节处理上也是不同的。这里去right为(x/2)+1,这是因为一个非负数x 阅读全文
posted @ 2017-07-19 10:48 王大咩的图书馆 阅读(1541) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings. 题意:找出所有字符串共同的最长前缀; 思路:因为是共同前缀,所以,求得第一个字符串和第二个字符的共同前缀以后,以这个前缀和后面 阅读全文
posted @ 2017-07-18 15:22 王大咩的图书馆 阅读(206) 评论(0) 推荐(0)
摘要:Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here a 阅读全文
posted @ 2017-07-18 10:46 王大咩的图书馆 阅读(345) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime 阅读全文
posted @ 2017-07-18 10:10 王大咩的图书馆 阅读(136) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime comple 阅读全文
posted @ 2017-07-18 09:35 王大咩的图书馆 阅读(219) 评论(0) 推荐(1)
摘要:Sort a linked list using insertion sort. 题意:使用插入排序排链表。 思路:所谓的插入排序法,可以理解为,从原链表中取结点,每次都从新的链表的开头开始遍历比较,在新链表中找到不小于当前节点的位置,然后将当前节点插入进去,依次重复这种过程,时间复杂度为O(n^2 阅读全文
posted @ 2017-07-17 18:15 王大咩的图书馆 阅读(178) 评论(0) 推荐(0)
摘要:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initia 阅读全文
posted @ 2017-07-17 16:48 王大咩的图书馆 阅读(201) 评论(0) 推荐(0)
摘要:Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are+,-,*,/. Each operand may be an integer or another expre 阅读全文
posted @ 2017-07-16 21:52 王大咩的图书馆 阅读(193) 评论(0) 推荐(1)
摘要:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. 阅读全文
posted @ 2017-07-16 20:19 王大咩的图书馆 阅读(180) 评论(0) 推荐(1)
摘要:Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring. For"(()", the longes 阅读全文
posted @ 2017-07-16 16:12 王大咩的图书馆 阅读(344) 评论(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 @ 2017-07-16 10:36 王大咩的图书馆 阅读(265) 评论(0) 推荐(0)
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. 题意:求全由1组成的最大矩形面积。 思路:这题感觉是larges 阅读全文
posted @ 2017-07-15 16:12 王大咩的图书馆 阅读(253) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 ··· 9 下一页