leetcode
weixin_37924880
这个作者很懒,什么都没留下…
展开
-
Leetcode: Max Points on a Line
Given n points on a 2D plane, find themaximum number of points that lie on the same straight line.(题意大概是找寻某一条直线,其上包含的点最多。)解决思路如下:(1)若点a与点b与点c在同一条直线上,那么它们的a和b,a和c所求的斜率是相等的。那么我们可以从第一个点s开始,以第一个点s为基原创 2017-12-13 19:04:18 · 159 阅读 · 0 评论 -
Leetcode: sum-root-to-leaf-numbers
Given a binary tree containingdigits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leafpath1->2->3which represents the number123. Find the total sum of a原创 2018-01-31 21:01:35 · 164 阅读 · 0 评论 -
Leetcode: surrounded-regions
Given a 2D boardcontaining'X'and'O', capture all regions surrounded by'X'. A region is captured by flippingall'O's into'X's in that surrounded region . For example:After running your funct原创 2018-01-31 21:00:21 · 182 阅读 · 0 评论 -
Leetcode:Candy
Leetcode: candyThere are N children standing in a line. Each child is assigned arating value.You are giving candies to these children subjected to the followingrequirements:Each child must hav原创 2018-01-07 10:56:37 · 298 阅读 · 0 评论 -
Leetcode: gas-station
There are N gas stations along a circular route, where the amountof gas at stationi isgas[i]. You have a car with an unlimited gas tank and it costscost[i]of gas totravel from stationi to its ne原创 2018-01-07 11:27:11 · 207 阅读 · 0 评论 -
Leetcode: single-number && single-number-ii
Given an array of integers, everyelement appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity.Could you implement it without using extra原创 2018-01-07 10:47:35 · 145 阅读 · 0 评论 -
Leetcode: palindrome-partitioning && palindrome-partitioning-ii
palindrome-partitioningGiven a string s, partition s such that every substring ofthe partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s. For example, g原创 2018-01-15 21:40:29 · 169 阅读 · 0 评论 -
Leetcode: linked-list-cycle-ii
Leetcode: linked-list-cycle-iiGiven a linked list, return the node where the cycle begins. If there isno cycle, returnnull.Follow up:Can you solve it without using extra space?思路:原创 2017-12-18 20:08:51 · 222 阅读 · 0 评论 -
Leetcode: reorder-list
Leetcode: reorder-list Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n→L 1→L n-1→L 2→L n-2→…You must do this in-place without alteringthe nodes' values.For exa原创 2017-12-18 20:08:10 · 186 阅读 · 0 评论 -
Leetcode: binary-tree-preorder-traversal(非递归版)
Leetcode: binary-tree-preorder-traversalGiven a binarytree, return the preorder traversal of itsnodes' values.思路:运用栈,根->左->右,先遍历左,那就需要先把右节点入栈,再将左节点入栈,这样出棧的时候,才能左节点先出,后出右节点。代码如下:vector preorder原创 2017-12-18 20:06:04 · 146 阅读 · 0 评论 -
Leetcode:binary-tree-postorder-traversal
Givena binary tree, return the postorder traversal of its nodes' values.后续遍历二叉树。递归思想:前遍历左子树,再遍历右子树,最后显示自身的值。代码如下: void postorder(TreeNode *root) { if(root != NULL) {原创 2017-12-14 13:37:16 · 152 阅读 · 0 评论 -
Leetcode:insertion-sort-list
Sort a linked list using insertion sort.提供两种思路,递归和非递归。递归思路:递归的对链表进行插入排序,递归直到链表末尾结束,然后进行插入排序。举个例子:4->6->5->7->2->3->null对其递归进行插入排序,那么会得到3->null。然后是2->3->null。然后当将7插入末尾链表的时候,对2->3->null进行遍历并比较原创 2017-12-14 11:50:14 · 134 阅读 · 0 评论 -
Leetcode: sort-list
Sorta linked list in O(n log n)time using constant space complexity.用O(nlogn)复杂度对链表进行排序,可以采用归并排序。那么需要对链表做如下操作:(1)将链表从中点划分为2个链表。(2)对左链表递归的进行归并排序(3)对右链表递归的进行归并排序(4)合并2个链表。举个例子:假如有一个链表为:4->原创 2017-12-14 10:37:51 · 133 阅读 · 0 评论 -
Leetcode:minimum-depth-of-binary-tree
Leetcode:minimum-depth-of-binary-treeGiven a binary tree, find its minimumdepth.The minimum depth is the number of nodes along the shortest path from theroot node down to the nearest leaf node.解原创 2017-12-13 20:01:27 · 141 阅读 · 0 评论 -
Leetcode: longest-consecutive-sequence
Given an unsorted array ofintegers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4原创 2018-01-31 21:02:01 · 167 阅读 · 0 评论