
leetcode
liqinzhe223
这个作者很懒,什么都没留下…
展开
-
leetcode 715. Range Module
A Range Module is a module that tracks ranges of numbers. Your task is to design and implement the following interfaces in an efficient manner.addRange(int left, int right) Adds the half-open原创 2018-04-10 10:23:26 · 729 阅读 · 0 评论 -
leetcode 235|236. Lowest Common Ancestor of a Tree
235. Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA原创 2018-04-09 10:17:12 · 317 阅读 · 0 评论 -
leetcode 587. Erect the Fence 凸包问题
问题如下: leetcode 587在一个二维的花园中,有一些用 (x,y) 坐标表示的树。由于安装费用十分昂贵,你的任务是先用最短的绳子围起所有的树。只有当所有的树都被绳子包围时,花园才能围好栅栏。你需要找到正好位于栅栏边界上的树的坐标。解法一:暴力解法我们知道凸包的性质,凸包一定是【最外围】的那些点圈成,所以假设有n个点,那么最多可以构造出n(n−1)2条边,算法如下: 1. 选定一条边,遍...原创 2018-04-03 14:34:46 · 1401 阅读 · 0 评论 -
网易2018实习生笔试编程题
牛牛的闹钟时间限制:1秒空间限制:32768K牛牛总是睡过头,所以他定了很多闹钟,只有在闹钟响的时候他才会醒过来并且决定起不起床。从他起床算起他需要X分钟到达教室,上课时间为当天的A时B分,请问他最晚可以什么时间起床 输入描述:每个输入包含一个测试用例。每个测试用例的第一行包含一个正整数,表示闹钟的数量N(N<=100)。接下来的N行每行包含两个整数,表示这个闹钟响起的时间为Hi(0&l...原创 2018-03-28 16:42:10 · 1129 阅读 · 0 评论 -
带父节点的二叉树的后序遍历 不使用递归和stack
#include #include #include #include using namespace std;class ListNode{public: ListNode(int k):val(k){ left = NULL; right = NULL; father = NULL; } ListNode*原创 2018-03-26 19:55:03 · 448 阅读 · 0 评论 -
美团2018暑期实习生笔试编程题
第一题:#include#include#includeusing namespace std;int num[20];int main(){ int num_a = 0, num_b = 0; string s, t; cin>>s; cin>>t; //滑动窗的思路 //1、先预处理,把 0-len原创 2018-03-23 10:06:51 · 1621 阅读 · 0 评论 -
leetcode 386. Lexicographical Numbers
Given an integer n, return 1 - n in lexicographical order.For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].Please optimize your algorithm to use less time and space. The input si原创 2018-03-21 13:36:47 · 199 阅读 · 0 评论 -
leetcode 297. Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be原创 2018-02-06 16:47:45 · 207 阅读 · 0 评论 -
leetcode 763. Partition Labels
763. Partition LabelsA string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a l原创 2018-01-25 19:15:43 · 369 阅读 · 0 评论 -
牛客 求1+2+3+...+n
题目描述求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。解答:使用短路原理。如果 ans = 0 那后面的递归就不会运行。class Solution {public: int Sum_Solution(int n) { int ans原创 2018-01-19 14:48:13 · 277 阅读 · 0 评论 -
leetcode 147. Insertion Sort List
147. Insertion Sort ListSort a linked list using insertion sort./*Sort a linked list using insertion sort. 链表的插入排序, 插入算法把要排序的数组分成两部分:第一部分包含了已经排序元素,而第二部分是未排序元素。将未排序元素 的第一个挨个和排序的比较,然后原创 2018-01-16 15:46:19 · 184 阅读 · 0 评论 -
546. Remove Boxes
546. Remove BoxesGiven several boxes with different colors represented by different positive numbers. You may experience several rounds to remove boxes until there is no box left. Each time原创 2018-01-16 11:22:23 · 421 阅读 · 0 评论 -
leetcode 576. Out of Boundary Paths
576. Out of Boundary PathsThere is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid boundary in four directi原创 2018-01-16 10:26:57 · 319 阅读 · 0 评论 -
leetcode 679. 24 Game
679. 24 GameYou have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, )to get the value of 24.Example 1:Input: [4,原创 2018-01-15 20:22:43 · 459 阅读 · 0 评论 -
leetcode 753. Cracking the Safe
753. Cracking the SafeThere is a box protected by a password. The password is n digits, where each letter can be one of the first k digits 0, 1, ..., k-1.You can keep inputting the pas原创 2018-01-15 14:29:27 · 848 阅读 · 0 评论 -
leetcode 733. Flood Fill
733. Flood FillAn image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).Given a coordinate (sr, sc) representing the原创 2018-01-15 10:43:10 · 599 阅读 · 0 评论 -
leetcode 695. Max Area of Island
695. Max Area of IslandGiven a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume al原创 2018-01-15 10:21:22 · 223 阅读 · 0 评论 -
leetcode 675. Cut Off Trees for Golf Event
675. Cut Off Trees for Golf EventYou are asked to cut off trees in a forest for a golf event. The forest is represented as a non-negative 2D map, in this map:0 represents the obstacle can'原创 2018-01-14 17:56:25 · 347 阅读 · 0 评论 -
leetcode 752. Open the Lock
752. Open the LockYou have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap aro原创 2018-01-14 15:34:15 · 381 阅读 · 0 评论 -
leetcode 743. Network Delay Time
743. Network Delay TimeThere are N network nodes, labelled 1 to N.Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the tar原创 2018-01-14 15:06:41 · 336 阅读 · 0 评论 -
leetcode 690. Employee Importance
690. Employee ImportanceYou are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id. For example,原创 2018-01-11 10:53:31 · 262 阅读 · 0 评论 -
leetcode 542. 01 Matrix
542. 01 MatrixGiven a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0O原创 2018-01-11 10:40:43 · 224 阅读 · 0 评论 -
leetcode 515. Find Largest Value in Each Tree Row
515. Find Largest Value in Each Tree RowYou need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5原创 2018-01-10 20:33:17 · 198 阅读 · 0 评论 -
leetcode 513. Find Bottom Left Tree Value
513. Find Bottom Left Tree ValueGiven a binary tree, find the leftmost value in the last row of the tree. Example 1:Input: 2 / \ 1 3Output:1Example 2: Input原创 2018-01-10 19:48:06 · 174 阅读 · 0 评论 -
leetcode 713. Subarray Product Less Than K
713. Subarray Product Less Than KYour are given an array of positive integers nums.Count and print the number of (contiguous) subarrays where the product of all the elements in the subarra原创 2018-01-10 17:40:34 · 257 阅读 · 0 评论 -
leetcode 632. Smallest Range
632. Smallest RangeYou have k lists of sorted integers in ascending order. Find the smallest range that includes at least one number from each of the klists. We define the range [a,b] is原创 2018-01-10 16:04:49 · 373 阅读 · 0 评论 -
leetcode 532. K-diff Pairs in an Array
532. K-diff Pairs in an ArrayGiven an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i原创 2018-01-10 14:58:23 · 203 阅读 · 0 评论 -
leetcode 567. Permutation in String
567. Permutation in StringGiven two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the sub原创 2018-01-10 14:28:19 · 167 阅读 · 0 评论 -
leetcode 403. Frog Jump
403. Frog JumpA frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the wat原创 2018-01-10 10:41:32 · 178 阅读 · 0 评论 -
leetcode 343. Integer Break
343. Integer BreakGiven a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For原创 2018-01-09 20:56:53 · 131 阅读 · 0 评论 -
leetcode 326. Power of Three
326. Power of ThreeGiven 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?要求不用任何形式循环得到 一个数是不是3的阶乘1、不用循原创 2018-01-09 17:14:46 · 128 阅读 · 0 评论 -
leetcode 338. Counting Bits
338. Counting BitsGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array原创 2018-01-09 17:05:17 · 191 阅读 · 0 评论 -
leetcode 365. Water and Jug Problem
365. Water and Jug ProblemYou are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measur原创 2018-01-09 16:48:43 · 182 阅读 · 0 评论 -
leetcode 436. Find Right Interval
436. Find Right IntervalGiven a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of the interval i,原创 2018-01-09 10:47:26 · 171 阅读 · 0 评论 -
leetcode 447. Number of Boomerangs
447. Number of BoomerangsGiven n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between i and j equals the distance原创 2018-01-09 10:05:52 · 141 阅读 · 0 评论 -
leetcode 443. String Compression
443. String CompressionGiven an array of characters, compress it in-place.The length after compression must always be smaller than or equal to the original array.Every element of the a原创 2018-01-05 11:24:38 · 235 阅读 · 0 评论 -
leetcode 438. Find All Anagrams in a String
438. Find All Anagrams in a StringGiven a string s and a non-empty string p, find all the start indices of p's anagrams in s.Strings consists of lowercase English letters only and the leng原创 2018-01-04 14:45:54 · 181 阅读 · 0 评论 -
leetcode 450. Delete Node in a BST
450. Delete Node in a BSTGiven a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.Basical原创 2018-01-02 19:48:43 · 186 阅读 · 0 评论 -
leetcode 441. Arranging Coins
441. Arranging CoinsYou have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that ca原创 2018-01-02 15:57:52 · 192 阅读 · 0 评论 -
leetcode 434. Number of Segments in a String
434. Number of Segments in a StringCount the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.Please note that the string does not contain原创 2018-01-02 15:50:12 · 161 阅读 · 0 评论