随笔分类 - Leetcode
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,...
阅读全文
摘要:Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histog...
阅读全文
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express...
阅读全文
摘要:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb...
阅读全文
摘要: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 ...
阅读全文
摘要:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.New version: 4ms 1 class S...
阅读全文
摘要:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.Analyse: Be cautious abou the expression of ...
阅读全文
摘要: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...
阅读全文
摘要:Implement pow(x,n).Analyse: To avoid exceeding time, first consider the basic situation, see line5~11; then set some precision s.t. when the differenc...
阅读全文
摘要:Implementint sqrt(int x).Compute and return the square root ofx.好的解法: 二分法,注意边界条件。当不满足循环条件时,low>high,经过验证,low-1为正确答案。时间:16ms 1 class Solution { 2 publi...
阅读全文
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".Analyse: Using XOR(^) to compute the result of ...
阅读全文
摘要: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.***Note**...
阅读全文
摘要:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe...
阅读全文
摘要:Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(...
阅读全文
摘要:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]...
阅读全文
摘要:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After re...
阅读全文
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings.Analyse: 找一些序列的最长前缀子序列。 1 class Solution { 2 public: 3 strin...
阅读全文
摘要:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.AC最快的一次。。每种字母代表一个数字。小的在左边表示右减左,小的在右边表示右加左。如I...
阅读全文
摘要:Determine whether an integer is a palindrome. Do this without extra space.Analyse:判断一个整数是否是回文数。注意负数都不是回文数。 1 class Solution { 2 public: 3 bool isP...
阅读全文
浙公网安备 33010602011771号