随笔分类 - Leetcode
摘要:Compare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion1 temp2) return 1;18 if(temp1 < temp2) return -1;19 ...
阅读全文
摘要:Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --...
阅读全文
摘要:Given apatternand a stringstr, find ifstrfollows the same pattern.Examples:pattern ="abba", str ="dog cat cat dog"should return true.pattern ="abba", ...
阅读全文
摘要:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a...
阅读全文
摘要:A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index....
阅读全文
摘要: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 num...
阅读全文
摘要:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially...
阅读全文
摘要: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],the...
阅读全文
摘要:Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume...
阅读全文
摘要:Find all possible combinations ofknumbers that add up to a numbern, given that only numbers from 1 to 9 can be used and each combination should be a u...
阅读全文
摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number ...
阅读全文
摘要:Given an Iterator class interface with methods:next()andhasNext(), design and implement a PeekingIterator that support thepeek()operation -- it essent...
阅读全文
摘要:Given an array of strings, group anagrams together.For example, given:["eat", "tea", "tan", "ate", "nat", "bat"],Return: 1 class Solution { 2 public: ...
阅读全文
摘要:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there will be on...
阅读全文
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matr...
阅读全文
摘要:Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.For example, givenn...
阅读全文
摘要:I. Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.Accordi...
阅读全文
摘要:Note:This is an extension ofHouse Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that h...
阅读全文
摘要:Find the total area covered by tworectilinearrectangles in a2Dplane.Each rectangle is defined by its bottom left corner and top right corner as shown ...
阅读全文
摘要:Given an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times. The algorithm should run in linear time and in O(1) space.Analys...
阅读全文
浙公网安备 33010602011771号