随笔分类 - LeetCode
摘要:题目描述: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 re...
阅读全文
摘要:题目描述: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 two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".解题方案: 1 class Solution { 2 public: 3 s...
阅读全文
摘要:题目描述: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 si...
阅读全文
摘要:题目描述:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transactio...
阅读全文
摘要:题目描述: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....
阅读全文
摘要:题目描述:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra spac...
阅读全文
摘要:题目描述:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?解题方案:使用快慢指针,如果有环,快指针肯定会追上慢指针。下面是该题的代码...
阅读全文
摘要:题目描述:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoint...
阅读全文
摘要:题目描述:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321解题方案:该题比较简单,直接贴代码: 1 class Solution { 2 public: 3 int ...
阅读全文
摘要:题目描述:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the t...
阅读全文
摘要:题目描述:Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime compl...
阅读全文
摘要:题目描述:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another ex...
阅读全文
摘要:题目描述:Sort a linked list inO(nlogn) time using constant space complexity.解题方案:题目要求的时间复杂度是O(nlogn),常数级空间复杂度。所以这里用了归并排序,归并排序在数组上操作比较方便,但是这里要排序的是链表。我们用到两个...
阅读全文
摘要:题目描述:Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime...
阅读全文
摘要:题目描述:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".解决方案:该题目解决思路很简单,新建一个字符串,然...
阅读全文
摘要:题目描述:Sort a linked list using insertion sort.解决方案:该题目就是用插入排序来对链表进行排序,很简单,直接上代码。 1 class Solution { 2 public: 3 ListNode *insertionSortList(ListNod...
阅读全文

浙公网安备 33010602011771号