随笔分类 - LeetCode
摘要:【题目】 Given an array of integers, find out whether there are two distinct indicesiandjin the array such that the difference betweennums[i]andnums[j]is...
阅读全文
摘要:【题目】 Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adj...
阅读全文
摘要:【题目】Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences o...
阅读全文
摘要:【题目】 删除一个整数链表里值为val的所有元素 举例: 假设有: 1-->2-->6-->3-->4-->5-->6 , val=6 返回有: 1-->2-->3-->4-->5【分析】 1. 链表删除问题 2. 把思路理清,多设几个指针。【算法实现】/** * Definition...
阅读全文
摘要:【题目】 写一个算法判断一个数是否"happy" 一个"happy"数的定义如下:开始于任意一个正整数,将该数替换为所有位上的数的平方和,然后重复这个过程直到这个数等于1,或者它可能无限循环(不包括1),这些结束于1的为"happy"数 举例: 19是一个"happy"数 12+92=8...
阅读全文
摘要:【题目】 你有n门课程需要完成,记为0到n-1。 有些课程需要先完成预备课程,例如你在完成课程0前需要先完成课程1,记为对[0,1]。 假如给定了课程总数以及所有预备关系对,返回完成所有课程的序列。 可能有多个正确序列,你需要返回其中一种。如果不能完成所有课程,就返回空数组。 举例:...
阅读全文
摘要:【题目】 你有n门课程需要上,几位0到n-1. 有些课程需要一些预备课程,例如:上课程0前需要先上课程1,表示为对[0,1] 假设给你所有课程和这些课程的对关系,有可能上完所有课程吗? 举例: 2 , [[1,0]] 这有2个课程需要完成,完成课程1前需要完成课程0,...
阅读全文
摘要:【题目】 假定给出一个有n个正整数的数组num和一个正整数s,找出一个子数组使其和sum大于s并返回子数组最小长度。如果不存在就返回0 举例:数组[2,3,1,2,4,3]和s=7 子数组[4,3]满足条件【分析】 1. 首先想到是两层for循环的方式,明显不会AC 2. 优化的方...
阅读全文
摘要:【题目】Given a list of non negative integers, arrange them such that they form the largest number.For example, given[3, 30, 34, 5, 9], the largest formed...
阅读全文
摘要:【题目】Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not pos...
阅读全文
摘要:【题目】You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?【analyze】1.先对角线...
阅读全文
摘要:【题目】Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after rainin...
阅读全文
摘要:【题目】Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "ad...
阅读全文
摘要:【题目】Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initi...
阅读全文
摘要:【题目】Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4]...
阅读全文
摘要:【题目】Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm shoul...
阅读全文
摘要:【题目】Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints...
阅读全文
摘要:【题目】Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].【analyze】1...
阅读全文
摘要:【题目】 Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in t...
阅读全文
摘要:【题目】Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted fr...
阅读全文

浙公网安备 33010602011771号