随笔分类 - Leetcode
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the
阅读全文
摘要:Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For exam...
阅读全文
摘要:Given an integer arraynums, find the sum of the elements between indicesiandj(i≤j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2)...
阅读全文
摘要:According to theWikipedia's article: "TheGame of Life, also known simply asLife, is a cellular automaton devised by the British mathematician John Hor...
阅读全文
摘要:Given an array containingndistinct numbers taken from0, 1, 2, ..., n, find the one that is missing from the array.For example,Givennums=[0, 1, 3]retur...
阅读全文
摘要: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"].Runtime: ...
阅读全文
摘要: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...
阅读全文
摘要:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example,If n = 4 and k = 2, a solution is: [ [2,4], [3,4
阅读全文
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique perm...
阅读全文
摘要: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
阅读全文
摘要:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 ston...
阅读全文
摘要:Follow upfor "Find Minimum in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Suppose a sort...
阅读全文
摘要:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephon...
阅读全文
摘要:Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))...
阅读全文
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).Find the minimum element.You m...
阅读全文
摘要:Given an array of numbersnums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements t...
阅读全文
摘要:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo...
阅读全文
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Runtime: 40ms 1 /** 2 * Definition for a point. 3 *...
阅读全文
摘要:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Runtime: 8ms 1 class Solution { 2 public...
阅读全文
摘要:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open(and closing parentheses), the plus+or minus...
阅读全文
浙公网安备 33010602011771号