- 博客(278)
- 收藏
- 关注
原创 LeetCode-top100
树:LeetCode94:Binary Tree Inorder TraversalLeetCode96:Unique Binary Search TreesLeetCode98:Validate Binary Search TreeLeetCode101:Symmetric TreeLeetCode102:Binary Tree Level Order Traversal...
2019-01-12 11:15:38 1782
原创 LeetCode
对做过的题目进行粗略的划分。紫色是top100。树:LeetCode94:Binary Tree Inorder TraversalLeetCode144:Binary Tree Preorder TraversalLeetCode145:Binary Tree Postorder TraversalLeetCode96:Unique Binary Search Trees...
2018-10-29 17:26:04 695
原创 剑指offer练习
数组(11道):剑指Offer_编程题01:二维数组中的查找剑指Offer_编程题06:旋转数组的最小数字剑指Offer_编程题13:调整数组顺序使奇数位于偶数前面剑指Offer_编程题28:数组中出现次数超过一半的数字剑指Offer_编程题30:连续子数组的最大和剑指Offer_编程题32:把数组排成最小的数剑指Offer_编程题35:数组中的逆序对(归并排序)剑...
2018-09-20 09:00:34 346 2
原创 剑指offer
现对这66道题目进行了粗略的划分,整理如下:数组(11道):剑指Offer_编程题01:二维数组中的查找剑指Offer_编程题06:旋转数组的最小数字(指针)剑指Offer_编程题13:调整数组顺序使奇数位于偶数前面剑指Offer_编程题28:数组中出现次数超过一半的数字剑指Offer_编程题30:连续子数组的最大和剑指Offer_编程题32:把数组排成最小的数剑指...
2018-08-15 15:09:13 781
原创 大数相乘
大数相乘,是指那些相乘结果或是乘数本身用long long类型都会溢出的数字,通常这些数字都通过string类型进行表示,借助于可动态调整大小的数据结构(vector,string,deque)模拟实现数字的乘法操作。对于普通的乘法,我们知道m位数和n位数相乘,最后的结果位数在区间内[m+n-1,m+n]。例如34*56,我们通常这么计算:将3,4分别于6相乘,记录低位的进位,然后将3,4对5...
2019-09-18 18:02:12 304
原创 LeetCode29:Divide Two Integers
Given two integersdividendanddivisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividingdividendbydivisor.The integer division sho...
2019-09-18 16:37:29 200
原创 数组dfs
给定一个二值图像(二维数组), 判断 p[h_i][w_i] p[h_j][w_j] 是否联通。class Solution: def moving(self, matrix, startx, starty, endx, endy): def dfs(matrix, startx, starty, endx, endy, rows, cols): ...
2019-08-30 11:10:49 533
原创 LeetCode340:Longest Substring with At Most K Distinct Characters
Given a string, find the length of the longest substring T that contains at mostkdistinct characters.For example, Given s =“eceba”and k = 2,T is "ece" which its length is 3.这道题是之前那道LeetCode1...
2019-08-21 20:31:28 242
原创 LeetCode159:Longest Substring with At Most Two Distinct Characters
Given a strings, find the length of the longest substringtthat containsat most2 distinct characters.Example 1:Input: "eceba"Output: 3Explanation: tis "ece" which its length is 3.Examp...
2019-08-21 20:27:25 158
原创 字符串变种
LeetCode242:Valid AnagramLeetCode76:Minimum Window SubstringLeetCode3:Longest Substring Without Repeating CharactersLeetCode438:Find All Anagrams in a StringLeetCode159:Longest Substring with ...
2019-08-16 09:40:24 143
原创 LeetCode921:Minimum Add to Make Parentheses Valid
Given a stringSof'('and')'parentheses, we add the minimum number of parentheses ('('or')', and in any positions ) so that the resulting parentheses string is valid.Formally, a parentheses s...
2019-04-19 14:48:51 171 1
原创 LeetCode109:Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the ...
2019-04-17 11:02:51 139
原创 归并排序
归并排序是建立在归并操作上的一种有效的排序算法,该算法是采用分治法(Divide and Conquer)的一个非常典型的应用。该算法采用经典的分治(divide-and-conquer)策略(分治法将问题分(divide)成一些小的问题然后递归求解,而治(conquer)的阶段则将分的阶段得到的各答案"修补"在一起,即分而治之)。分阶段可以理解为就是递归拆分子序列的过程,递归深度为log...
2019-04-15 15:30:12 116
原创 百度2017暑期笔试[编程题] 构造回文
给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串。如何删除才能使得回文串最长呢?输出需要删除的字符个数。输入描述:输入数据有多组,每组包含一个字符串s,且保证:1<=s.length<=1000.输出描述:对于每组数据,输出一个整数,代表最少需要删除的字符个数。输入例子1:abcdagoogle输出例子1:22回文串的特点...
2019-04-07 16:20:44 172
原创 非极大值抑制NMS
非极大值抑制的方法是:先假设有6个矩形框,根据分类器的类别分类概率做排序,假设从小到大属于车辆的概率分别为A、B、C、D、E、F。(1)从最大概率矩形框F开始,分别判断A~E与F的重叠度IOU是否大于某个设定的阈值;(2)假设B、D与F的重叠度超过阈值,那么就扔掉B、D;并标记第一个矩形框F,是我们保留下来的。(3)从剩下的矩形框A、C、E中,选择概率最大的E,然后判断E与A、C的重叠...
2019-03-15 11:38:05 222
原创 计算IOU
参考链接:Intersection over Union (IoU) for object detection候选框面积算的是像素点数,比如候选框左上和右下点坐标相同时,面积应该为1,如果计算面积时不+1,候选框面积就变成0了。#!/usr/bin/env python# encoding: utf-8 def compute_iou(rec1, rec2): """ ...
2019-03-15 11:16:04 1054
原创 LeetCode145:Binary Tree Postorder Traversal
Given a binary tree, return thepostordertraversal of its nodes' values.Example:Input:[1,null,2,3] 1 \ 2 / 3Output:[3,2,1]Follow up:Recursive solution is trivial, could ...
2019-03-12 11:03:05 198
原创 LeetCode144:Binary Tree Preorder Traversal
Given a binary tree, return thepreordertraversal of its nodes' values.Example:Input:[1,null,2,3] 1 \ 2 / 3Output:[1,2,3]Follow up:Recursive solution is trivial, could ...
2019-03-12 10:27:18 297
原创 百度2017春招笔试[编程题] 有趣的排序
度度熊有一个N个数的数组,他想将数组从小到大排好序,但是萌萌的度度熊只会下面这个操作:任取数组中的一个数然后将它放置在数组的最后一个位置。问最少操作多少次可以使得数组从小到大有序?输入描述:首先输入一个正整数N,接下来的一行输入N个整数。(N <= 50, 每个数的绝对值小于等于1000)输出描述:输出一个整数表示最少的操作次数。输入例子1:4...
2019-03-11 20:01:52 569
原创 百度2017春招笔试[编程题] 度度熊回家
一个数轴上共有N个点,第一个点的坐标是度度熊现在位置,第N-1个点是度度熊的家。现在他需要依次的从0号坐标走到N-1号坐标。但是除了0号坐标和N-1号坐标,他可以在其余的N-2个坐标中选出一个点,并直接将这个点忽略掉,问度度熊回家至少走多少距离?输入描述:输入一个正整数N, N <= 50。接下来N个整数表示坐标,正数表示X轴的正方向,负数表示X轴的负方向。绝对值小于等于10...
2019-03-11 17:01:05 320
原创 百度2017春招笔试[编程题] 买帽子
度度熊想去商场买一顶帽子,商场里有N顶帽子,有些帽子的价格可能相同。度度熊想买一顶价格第三便宜的帽子,问第三便宜的帽子价格是多少?输入描述:首先输入一个正整数N(N <= 50),接下来输入N个数表示每顶帽子的价格(价格均是正整数,且小于等于1000)输出描述:如果存在第三便宜的帽子,请输出这个价格是多少,否则输出-1输入例子1:1010 10 10 10...
2019-03-11 16:59:22 233
原创 LeetCode223:Rectangle Area
Find the total area covered by tworectilinearrectangles in a2Dplane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Example:Input: A = -3, ...
2019-03-11 14:54:57 148
原创 LeetCode836:Rectangle Overlap
A rectangle isrepresented as alist[x1, y1, x2, y2], where(x1, y1)are the coordinates of its bottom-left corner, and(x2,y2)are the coordinates of its top-right corner.Two rectangles overlap i...
2019-03-11 14:43:28 189
原创 LeetCode199:Binary Tree Right Side View
Given a binary tree, imagine yourself standing on therightside of it, return the values of the nodes you can see ordered from top to bottom.Example:Input:[1,2,3,null,5,null,4]Output:[1, 3, 4...
2019-03-06 14:56:50 149
原创 LeetCode301:Remove Invalid Parentheses
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note:The input string may contain letters other than the parentheses(and)....
2019-01-17 10:29:01 266
原创 LeetCode146:LRU Cache
Design and implement a data structure forLeast Recently Used (LRU) cache. It should support the following operations:getandput.get(key)- Get the value (will always be positive) of the key if th...
2019-01-17 09:43:05 189
原创 LeetCode72:Edit Distance
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a character Delete a chara...
2019-01-16 10:48:33 218
原创 LeetCode32:Longest Valid Parentheses
Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest valid...
2019-01-16 10:22:11 204
原创 LeetCode312:Burst Balloons
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[le...
2019-01-16 09:44:07 507
原创 LeetCode208:Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Example:Trie trie = new Trie();trie.insert("apple");trie.search("apple"); // returns truetrie.search("app"); // returns fals...
2019-01-16 09:11:00 138
原创 LeetCode239:Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window m...
2019-01-12 11:11:17 210
原创 LeetCode128:Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input:[100, 4, 200, 1, 3, 2]Output: 4Ex...
2019-01-12 10:25:48 194
原创 LeetCode207:Course Schedule
There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair...
2019-01-12 09:27:33 272
原创 LeetCode200:Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume...
2019-01-11 11:02:54 219
原创 LeetCode253:Meeting Rooms II
Given an array of meeting time intervals consisting of start and end times[[s1,e1],[s2,e2],...](si< ei), find the minimum number of conference rooms required.For example,Given[[0, 30],[5, 10...
2019-01-11 10:24:22 570
原创 LeetCode621:Task Scheduler
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks. Tasks could be done without original order. Each task could ...
2019-01-11 09:15:20 152
原创 LeetCode238:Product of Array Except Self
Given an arraynumsofnintegers wheren> 1, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Example:Input: [1,2,3,4]Output: ...
2019-01-10 11:20:42 155
原创 LeetCode406:Queue Reconstruction by Height
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), wherehis the height of the person andkis the number of people in front of this ...
2019-01-10 11:03:24 146
原创 LeetCode394:Decode String
Given an encoded string, return it's decoded string.The encoding rule is:k[encoded_string], where theencoded_stringinside the square brackets is being repeated exactlyktimes. Note thatkis gua...
2019-01-10 10:25:45 198
原创 LeetCode56:Merge Intervals
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps...
2019-01-10 09:35:12 300
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人