随笔分类 -  LeetCode

上一页 1 ··· 4 5 6 7 8 9 下一页
摘要:一.Ugly NumberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3,... 阅读全文
posted @ 2015-11-28 10:13 zengzy 阅读(196) 评论(0) 推荐(0)
摘要:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.如果直接遍历链表数组,时间复杂度为T(n)=T(n-1)+o(lenn);即合并前n-1个链表的时间+与第n... 阅读全文
posted @ 2015-11-28 09:36 zengzy 阅读(131) 评论(0) 推荐(0)
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Def... 阅读全文
posted @ 2015-11-28 01:56 zengzy 阅读(124) 评论(0) 推荐(0)
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great... 阅读全文
posted @ 2015-11-28 01:50 zengzy 阅读(148) 评论(0) 推荐(0)
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".class Solution {public: string addBinary(str... 阅读全文
posted @ 2015-11-28 01:37 zengzy 阅读(193) 评论(0) 推荐(0)
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文
posted @ 2015-11-28 01:15 zengzy 阅读(154) 评论(0) 推荐(0)
摘要:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-nega... 阅读全文
posted @ 2015-11-28 00:15 zengzy 阅读(204) 评论(0) 推荐(0)
摘要:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at... 阅读全文
posted @ 2015-11-27 22:22 zengzy 阅读(178) 评论(0) 推荐(0)
摘要:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.要求空间复杂度为o(1)思路:把数组划分为两部分,第一部分是第一行和第一列;第二部分是除去第一行第一列的矩阵部分。1.先记... 阅读全文
posted @ 2015-11-27 21:50 zengzy 阅读(183) 评论(0) 推荐(0)
摘要:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"].class Sol... 阅读全文
posted @ 2015-11-27 20:29 zengzy 阅读(138) 评论(0) 推荐(0)
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fol... 阅读全文
posted @ 2015-11-23 22:04 zengzy 阅读(218) 评论(0) 推荐(0)
摘要:一.Pascal's TriangleGivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,... 阅读全文
posted @ 2015-11-23 20:51 zengzy 阅读(142) 评论(0) 推荐(0)
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文
posted @ 2015-11-14 13:16 zengzy 阅读(159) 评论(0) 推荐(0)
摘要:这是使用DFS来解数组类题的典型题目,像求子集,和为sum的k个数也是一个类型 解题步骤: 1:有哪些起点,例如,数组中的每个元素都有可能作为起点,那么用个for循环就可以了。 2:是否允许重复组合 3:处理某个数,判断结果 4:dfs递归 5:还原现场 一:Permutations Given a 阅读全文
posted @ 2015-11-13 12:21 zengzy 阅读(457) 评论(0) 推荐(0)
摘要:一:Majority ElementGiven an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may a... 阅读全文
posted @ 2015-11-12 23:28 zengzy 阅读(180) 评论(0) 推荐(0)
摘要:以下三个问题的典型的两个指针处理数组的问题,一个指针用于遍历,一个指针用于指向当前处理到位置 一:Remove Element Given an array and a value, remove all instances of that value in place and return the 阅读全文
posted @ 2015-11-12 23:15 zengzy 阅读(222) 评论(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 @ 2015-11-12 21:21 zengzy 阅读(196) 评论(0) 推荐(0)
摘要:Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文
posted @ 2015-11-12 16:06 zengzy 阅读(189) 评论(0) 推荐(0)
摘要:Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh... 阅读全文
posted @ 2015-11-12 15:04 zengzy 阅读(177) 评论(0) 推荐(0)
摘要:一:Find Minimum in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 阅读全文
posted @ 2015-11-12 14:55 zengzy 阅读(166) 评论(0) 推荐(0)

上一页 1 ··· 4 5 6 7 8 9 下一页
levels of contents