自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(117)
  • 收藏
  • 关注

转载 [LeetCode]114. Power of Three 三的幂

Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?解法1:不断除去n的因子3,最后判断是否为1class Solution {public:...

2016-01-29 16:33:00 175

转载 [LeetCode]113. Maximum Depth of Binary Tree二叉树的最大深度

Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.解法1:很简单的DFS递归。/** * Defi...

2015-12-25 19:25:00 178

转载 [LeetCode]112. Maximum Subarray最大和连续子序列

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,−5,4],the contiguous subarray[4,−1,2,1]h...

2015-12-16 10:20:00 199

转载 [LeetCode]111. Find Minimum in Rotated Sorted Array II旋转数组最小值II

Follow upfor "Find Minimum in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pi...

2015-12-15 11:02:00 150

转载 [LeetCode]110. Find Minimum in Rotated Sorted Array旋转数组最小值

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 may assume no duplicate exists in the...

2015-12-15 09:33:00 96

转载 [LeetCode]109. Construct Binary Tree from Inorder and Postorder Traversal由中序序列和后序序列重建二叉树...

Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.解法:这题和由前序序列和中序序列重建二叉树一样,解法也相同,不过是先根据后序序列的最后一个元素为树根,再...

2015-12-14 18:43:00 121

转载 [LeetCode]108. Construct Binary Tree from Preorder and Inorder Traversal由前序序列和中序序列重建二叉树...

Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.解法:前序遍历的第一个元素为树根,因为树中无重复元素,因此遍历一遍可以在中序序列中找出树根所在位置,于是把...

2015-12-14 18:38:00 70

转载 [LeetCode]107. Best Time to Buy and Sell Stock III股票买卖III

Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may n...

2015-12-11 20:14:00 74

转载 [LeetCode]106. Best Time to Buy and Sell Stock II股票买卖II

Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy...

2015-12-11 13:55:00 89

转载 [LeetCode]105. Word Search单词查找

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 "adjacent" cells are those horizontally or vertica...

2015-12-11 11:31:00 100

转载 [LeetCode]104. Basic Calculator II基本计算器

Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty spaces. The integer division shoul...

2015-12-09 15:16:00 113

转载 [LeetCode]103. Find the Duplicate Number重复值查找

Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate numbe...

2015-12-09 11:21:00 91

转载 [LeetCode]102. Product of Array Except Self数组乘积

Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Solve itwithout divisionand in...

2015-12-09 09:18:00 96

转载 [LeetCode]101. Trapping Rain Water收集雨水

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 raining.For example,Given[0,1,0,2,1,0,1,3,2,1,2,1...

2015-12-08 19:56:00 99

转载 [LeetCode]100. Remove Duplicates from Sorted Array II排序数组去重

Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted arraynums=[1,1,1,2,2,3],Your function should return length =5, with the first five ...

2015-12-08 19:05:00 68

转载 [LeetCode]99. Container with Most Water最大容积

Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find...

2015-12-05 11:35:00 68

转载 [LeetCode]98. SortColors颜色排序

Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the intege...

2015-12-04 20:53:00 81

转载 [LeetCode]97. Reorder List链表重排序

Given a singly linked list L: 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 example,Given {1,2,3,4}, reorder ...

2015-12-04 10:10:00 92

转载 [LeetCode]96. Min Stack带Min函数的栈

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top(...

2015-11-19 14:46:00 119

转载 [LeetCode]95. Implement Stack using Queues用队列实现栈

Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- ...

2015-11-19 11:26:00 66

转载 [LeetCode]94. Implement Queue using Stacks用栈实现队列

Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front eleme...

2015-11-19 10:31:00 78

转载 [LeetCode]93. Linked List Cycle II查找链表中环的起始节点

Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Note:Do not modify the linked list.Follow up:Can you solve it without using extra space?...

2015-11-18 10:38:00 108

转载 [LeetCode]92. Linked List Cycle判断链表是否有环

Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Subscribeto see which companies asked this question解法1:使用两个指针p1, p...

2015-11-17 20:01:00 82

转载 [LeetCode]91. Rotate List旋转链表

Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.S...

2015-11-17 18:25:00 85

转载 [LeetCode]90. Reverse Linked List II链表局部反转

Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No...

2015-11-17 11:00:00 225

转载 [LeetCode]89. Partition List链表划分

Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each...

2015-11-16 19:50:00 77

转载 [LeetCode]88. Swap Nodes in Pairs链表成对逆序

Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only ...

2015-11-16 18:58:00 53

转载 [LeetCode]87. Remove Duplicates from Sorted List II排序链表去重II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1-...

2015-11-16 16:19:00 70

转载 [LeetCode]86. Sort List链表排序

Sort a linked list inO(nlogn) time using constant space complexity.Subscribeto see which companies asked this question解法:这题和Insertion Sort List链表插入排序一样,都是要求对单链表进行排序,但是本题要求时间复杂度在O(...

2015-11-16 15:25:00 64

转载 [LeetCode]85. Insertion Sort List链表插入排序

Sort a linked list using insertion sort.Subscribeto see which companies asked this question解法:设置3个指针:应插入位置的前一个节点first、当前处理节点third和其前一个节点second,设置辅助节点help指向头节点。然后从头节点的next节点开始遍历,一个个插入...

2015-11-16 13:04:00 91

转载 [LeetCode]84. Remove Linked List Elements移除链表元素

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 --> 4 --> ...

2015-11-16 10:41:00 83

转载 [LeetCode]83. Intersection of Two Lists两条单链表的交点

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: a1 → a2 ↘ ...

2015-11-16 10:17:00 106

转载 [LeetCode]82. Remove Duplicates from Sorted List排序链表去重

Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3....

2015-11-16 09:24:00 64

转载 [LeetCode]81. Palindrome Linked List回文链表

Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?Subscribeto see which companies asked this question解...

2015-11-15 16:25:00 75

转载 [LeetCode]80. Merge Two Sorted Lists合并两个排序链表

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.Subscribeto see which companies asked this que...

2015-11-15 10:33:00 66

转载 [LeetCode]79. Delete Node in a Linked List删除链表节点

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> 4and you are given the third nod...

2015-11-14 19:22:00 66

转载 [LeetCode]78. Remove Nth Node From end of List删除链表中倒数第N个节点

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 removing the second node ...

2015-11-14 18:46:00 49

转载 [LeetCode]77. Reverse Linked List反转链表

Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?Subscribeto see which companie...

2015-11-13 19:45:00 68

转载 [LeetCode]76. Permutation Sequence全排列序列

The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123""132""213""2...

2015-11-13 10:30:00 89

转载 [LeetCode]75. Pow(x,n)幂运算

Implement pow(x,n).Subscribeto see which companies asked this question解法1:最简单的即是n个x直接相乘,毫无疑问会超时Time Limit Exceededclass Solution {public: double myPow(double x, int n) {...

2015-11-12 18:56:00 102

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除