
Leetcode
Snail_Walker
Google Senior Machine Learning Tech Lead | 行胜于言
展开
-
Leetcode之Graph and Search
graphReconstruct ItineraryCut Off Trees for Golf EventNumber of IslandsFriend CirclesWord LadderRedundant ConnectionEmployee ImportanceCourse ScheduleCourse Schedule IINetwork Delay Time原创 2018-01-08 01:50:31 · 501 阅读 · 0 评论 -
Leetcode之Greedy和Heap
HeapTop K Frequent WordsFind Median from Data StreamGreedyCreate Maximum NumberCut Off Trees for Golf EventTask SchedulerLongest PalindromeValid Triangle NumberAssign CookiesMaximum Pr原创 2018-01-06 05:49:14 · 439 阅读 · 0 评论 -
Leetcode 刷题之链表和位操作
reverse Linked Listbit operationreverse Linked List206. Reverse Linked List/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * L原创 2017-12-25 01:20:27 · 273 阅读 · 0 评论 -
669. Trim a Binary Search Tree/110. Balanced Binary Tree/443. String Compression/266. Palindrome Per
669. Trim a Binary Search TreeGiven a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the r原创 2017-11-21 21:57:05 · 329 阅读 · 0 评论 -
551. Student Attendance Record I
551. Student Attendance Record IProblem DescriptionYou are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent.'L' : La原创 2017-08-08 14:51:37 · 384 阅读 · 0 评论 -
646. Maximum Length of Pair Chain/640. Solve the Equation
646. Maximum Length of Pair ChainProblem DescriptionYou are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow an原创 2017-08-07 13:49:35 · 437 阅读 · 0 评论 -
29. Divide Two Integers/49. Group Anagrams/96. Unique Binary Search Trees/560. Subarray Sum Equals K
Divide Two IntegersProblem DescriptionImplementation29. Divide Two IntegersProblem DescriptionDivide two integers without using multiplication, division and mod operator.If it is overflow, return MAX原创 2017-07-30 14:42:37 · 576 阅读 · 0 评论 -
645. Set Mismatch/598. Range Addition II/319. Bulb Switcher/374. Guess Number Higher or Lower
Set MismatchProblem DescriptionImplementation645. Set MismatchProblem DescriptionThe set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the原创 2017-07-25 12:58:39 · 682 阅读 · 0 评论 -
292. Nim Game/504. Base 7
292. Nim GameProblem DescriptionYou 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 stones. The one who rem原创 2017-07-21 09:30:25 · 344 阅读 · 0 评论 -
C++: 二维数组作函数参数
变量在作用域里面被声明的是什么类型,就当作什么类型来用。(1)参数是二维数组,但是要指定第二维的维数。int array[10][10];函数声明:void fuc(int a[][10]);函数调用:fuc(array);——在函数fuc中,a是二维数组。使用a[i][j]形式来访问数组中元素。(2)参数使用一维指针数组。int *array[10];for(i转载 2017-07-20 09:30:32 · 792 阅读 · 0 评论 -
extern 用法,全局变量与头文件(重复定义)
用#include可以包含其他头文件中变量、函数的声明,为什么还要extern关键字,如果我想引用一个全局变量或函数a,我只要直接在源文件中包含#include首先说下头文件,其实头文件对计算机而言没什么作用,她只是在预编译时在#include的地方展开一下,没别的意义了,其实头文件主要是给别人看的。我做过一个实验,将头文件的后缀改成xxx.txt,然后在引用该头文件的地方用#include"x转载 2017-07-19 09:44:58 · 1608 阅读 · 0 评论 -
617. Merge Two Binary Trees
617. Merge Two Binary TreesProblemGiven two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to me原创 2017-07-16 22:32:54 · 361 阅读 · 0 评论 -
637. Average of Levels in Binary Tree\633. Sum of Square Numbers\643. Maximum Average Subarray I
Average of Levels in Binary TreeProblemImplementationSum of Square NumbersProblem DescriptionImplementationMaximum Average Subarray IDescriptionImplementation637. Average of Levels in Binary Tr原创 2017-07-16 20:33:56 · 713 阅读 · 0 评论 -
475. Heaters
475. HeatersProblemWinter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.Now, you are given positions of houses and heaters on原创 2017-07-16 01:34:40 · 296 阅读 · 0 评论 -
606. Construct String from Binary Tree
606. Construct String from Binary TreeProblemYou need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represente原创 2017-07-15 21:14:20 · 301 阅读 · 0 评论 -
621. Task Scheduler
Task SchedulerProblemImplmentation621. Task SchedulerProblemGiven a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.原创 2017-07-15 20:11:12 · 522 阅读 · 0 评论 -
628. Maximum Product of Three Numbers
Maximum Product of Three NumbersProblemImplementation628. Maximum Product of Three NumbersProblemGiven an integer array, find three numbers whose product is maximum and output the maximum product.Exa原创 2017-07-15 19:49:58 · 356 阅读 · 0 评论 -
599. Minimum Index Sum of Two Lists
599. Minimum Index Sum of Two ListsdescriptionSuppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.You need to help th原创 2017-06-15 20:54:41 · 341 阅读 · 0 评论 -
605. Can Place Flowers/611. Valid Triangle Number/575. Distribute Candies
Can Place FlowersdescriptionimplementationValid Triangle Numberdescriptionimplementation605. Can Place FlowersdescriptionSuppose you have a long flowerbed in which some of the plots are planted an原创 2017-06-12 22:11:31 · 534 阅读 · 0 评论 -
566. Reshape the Matrix/624. Maximum Distance in Arrays/594. Longest Harmonious Subsequence
Reshape the Matrixdescriptionimplementation566. Reshape the MatrixdescriptionIn MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size原创 2017-06-07 09:38:17 · 461 阅读 · 0 评论 -
561. Array Partition I/581. Shortest Unsorted Continuous Subarray
Array Partition Idescriptionimplementation561. Array Partition IdescriptionGiven an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (a原创 2017-06-06 10:19:04 · 422 阅读 · 0 评论 -
150. Evaluate Reverse Polish Notation
Evaluate Reverse Polish NotationDescriptionImplementation150. Evaluate Reverse Polish NotationDescriptionEvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are原创 2017-06-05 22:44:38 · 331 阅读 · 0 评论 -
173. Binary Search Tree Iterator
Binary Search Tree IteratorDescriptionImplementation173. Binary Search Tree IteratorDescriptionmplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root no转载 2017-06-05 22:23:54 · 460 阅读 · 0 评论 -
224. Basic Calculator
Problem DescriptionImplementation By CProblem DescriptionImplement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plu原创 2017-05-31 22:52:58 · 317 阅读 · 0 评论 -
114. Flatten Binary Tree to Linked List\538. Convert BST to Greater Tree
DESCRIPTIONIMPLEMENTATION DESCRIPTIONGiven a binary tree, flatten it to a linked list in-place.For example,Given : 1 / \ 2 5 / \ \ 3 4 6The flattened tree sho原创 2017-04-14 09:59:08 · 336 阅读 · 0 评论 -
557. Reverse Words in a String III\521. Longest Uncommon Subsequence I
Reverse Words in a String IIIDESCRIPTIONIMPLEMENTATIONLongest Uncommon Subsequence IDESCRIPTIONIMPLEMENTATION557. Reverse Words in a String IIIDESCRIPTIONGiven a string, you need to reverse the or原创 2017-04-12 09:52:19 · 505 阅读 · 0 评论 -
543. Diameter of Binary Tree
Diameter of Binary Treedescriptionimplementation543. Diameter of Binary TreedescriptionGiven a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree i原创 2017-04-10 20:20:02 · 756 阅读 · 0 评论 -
210. Course Schedule II\199. Binary Tree Right Side View\279. Perfect Squares
Course Schedule IIDESCRIPTIONIMPLEMENTATION210. Course Schedule IIDESCRIPTIONThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example原创 2017-04-10 10:52:30 · 674 阅读 · 0 评论 -
137. Single Number II\393. UTF-8 Validation\547. Friend Circles
Single Number IIDESCRIPTIONIMPLEMENTATIONUTF-8 ValidationDESCRIPTIONIMPLEMENTATION137. Single Number IIDESCRIPTIONGiven an array of integers, every element appears three times except for one, whic原创 2017-04-09 19:57:32 · 633 阅读 · 0 评论 -
371. Sum of Two Integers\318. Maximum Product of Word Lengths\208. Implement Trie\201.Bitwise AND
Sum of Two IntegersDESCRIPTIONIMPLEMENTATIONMaximum Product of Word LengthsDESCRIPTIONIMPLEMENTATION371. Sum of Two IntegersDESCRIPTIONCalculate the sum of two integers a and b, but you are not al原创 2017-04-09 11:29:35 · 521 阅读 · 0 评论 -
京东2017机试题目总结
站队终结者C站队有一条很长的队伍,队伍里面一共有n个人。所有的人分为三类:警察,小偷和普通人。将队伍里面的人从前到后由1到n编号,编号为i的人与编号为j的人的距离为i与j之差的绝对值。每一个警察有一个能力值x,表示他能够监视与他距离不超过x的所有人,小偷被警察发现当且仅当他被一个或多个警察监视到。你知道在整条队伍中,一共有多少个小偷会被警察发现吗?在【1】中有所有的2017年京东的题目。这道题目,原创 2017-04-08 23:49:30 · 580 阅读 · 0 评论 -
523. Continuous Subarray Sum
Continuous Subarray Sumdescriptionimplementation523. Continuous Subarray SumdescriptionGiven a list of non-negative numbers and a target integer k, write a function to check if the array has a contin原创 2017-04-08 00:11:31 · 437 阅读 · 0 评论 -
447. Number of Boomerangs\187. Repeated DNA Sequences\537. Complex Number Multiplication
Number of BoomerangsDESCRIPTIONIMPLEMENTATION447. Number of BoomerangsDESCRIPTIONGiven n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the原创 2017-04-07 14:30:02 · 293 阅读 · 0 评论 -
421. Maximum XOR of Two Numbers in an Array
Maximum XOR of Two Numbers in an Arraydescriptionimplementation421. Maximum XOR of Two Numbers in an ArraydescriptionGiven a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find原创 2017-04-06 23:50:52 · 388 阅读 · 0 评论 -
211. Add and Search Word - Data structure design
descriptionimplementationdescriptionDesign a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expressi原创 2017-04-06 11:46:49 · 322 阅读 · 0 评论 -
190. Reverse Bits\331. Verify Preorder Serialization of a Binary Tree
Reverse BitsdescriptionimplementationVerify Preorder Serialization of a Binary Treedescriptionimplementation190. Reverse BitsdescriptionReverse bits of a given 32 bits unsigned integer.For example原创 2017-04-05 14:13:07 · 540 阅读 · 0 评论 -
148. Sort List\191. Number of 1 Bits\476. Number Complement\342. Power of Four
题目描述代码实现题目描述Sort a linked list in O(n log n) time using constant space complexity.对一个链表进行排序,时间复杂度为O(n log n),空间复杂度为O(1),所以这道题目的限制还是比较多。由于链表的索引不是很方便,所以首先可以想到使用归并排序,那么时间复杂度为O(n log n)。然后又因为空间复杂度为O(1),那么原创 2017-04-03 21:13:52 · 439 阅读 · 0 评论 -
126. Word Ladder II \ 507. Perfect Number
Word Ladder II题目描述代码实现Perfect Number题目描述代码实现26. Word Ladder II题目描述Given two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord原创 2017-03-29 15:16:23 · 575 阅读 · 0 评论 -
两个小时重温C++
面向对象的思想面向对象的思想封装封装意味着把对象的属性和方法结合成一个独立的系统单位,并尽可能隐藏对象的内部细节。比如一个手电筒,我们不要关心它的内部实现机制,它的电路等等,我们只要了解开关(输入)和灯的亮度(输出)。抽象抽象的过程是对具体问题进行概括的过程,是对一类公共问题进行统一描述的过程。为了使某些必要的信息得以顺利的交流,设计者必须制定一个抽象,就如同一个协议,一个得到所有参与活动的有效个体原创 2017-03-29 01:13:25 · 665 阅读 · 0 评论 -
154. Find Minimum in Rotated Sorted Array II \ 128. Longest Consecutive Sequence
Find Minimum in Rotated Sorted Array II题目解析代码实现154. Find Minimum in Rotated Sorted Array II题目解析Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1原创 2017-03-28 14:37:19 · 396 阅读 · 0 评论