![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
秋招
BUPT-WT
不积硅步无以至千里,不积小流无以成江海
展开
-
Leetcode - 695. Max Area of Island (DFS)
Given a non-empty 2D arraygridof 0's and 1's, anislandis a group of1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrou...原创 2019-08-24 08:51:39 · 179 阅读 · 0 评论 -
Leetcode - 583. Delete Operation for Two Strings (字符串编辑)
Given two wordsword1andword2, find the minimum number of steps required to makeword1andword2the same, where in each step you can delete one character in either string.Example 1:Input: "sea...原创 2019-08-24 08:51:31 · 147 阅读 · 0 评论 -
Leetcode - 416. Partition Equal Subset Sum (0-1背包)
Given anon-emptyarray containingonly positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the array eleme...原创 2019-08-24 08:51:24 · 132 阅读 · 0 评论 -
Leetcode - 343. Integer Break (分割整数)
Given a positive integern, break it into the sum ofat leasttwo positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input: 2Output: 1...原创 2019-08-24 08:51:18 · 128 阅读 · 0 评论 -
Leetcode - 309. Best Time to Buy and Sell Stock with Cooldown (股票交易)
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 one ...原创 2019-08-22 09:28:36 · 126 阅读 · 0 评论 -
Leetcode - 303. Range Sum Query - Immutable (数组区间)
Given an integer arraynums, find the sum of the elements between indicesiandj(i≤j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sum...原创 2019-08-22 09:11:55 · 77 阅读 · 0 评论 -
Leetcode - 279. Perfect Squares (BFS)
Given a positive integern, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum ton.Example 1:Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4.Example...原创 2019-08-22 08:57:43 · 119 阅读 · 0 评论 -
Leetcode - 70. Climbing Stairs (斐波那契额数列)
You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note:Givennwill be a positive...原创 2019-08-22 08:31:52 · 97 阅读 · 0 评论 -
Leetcode - 64. Minimum Path Sum (矩阵路径)
Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at a...原创 2019-08-22 08:24:19 · 133 阅读 · 0 评论 -
Leetcode - 513. Find Bottom Left Tree Value (层次遍历)
Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2:Input: 1 / \ 2 3 / / \...原创 2019-08-22 07:48:53 · 83 阅读 · 0 评论 -
Leetcode - 230. Kth Smallest Element in a BST (BST)
Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Example 1:Input: root = [3,...原创 2019-08-22 07:48:45 · 113 阅读 · 0 评论 -
Leetcode - 208. Implement Trie (Prefix Tree) (Trie)
Implement a trie withinsert,search, andstartsWithmethods.Example:Trie trie = new Trie();trie.insert("apple");trie.search("apple"); // returns truetrie.search("app"); // returns fals...原创 2019-08-22 07:48:34 · 112 阅读 · 0 评论 -
Leetcode - 144. 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-08-22 07:48:18 · 101 阅读 · 0 评论 -
Leetcode - 110. Balanced Binary Tree(递归)
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the depth of the two subtrees ofeverynode never diff...原创 2019-08-22 07:47:58 · 85 阅读 · 0 评论 -
Leetcode - 169. Majority Element (多数投票问题)
Given an array of sizen, find the majority element. The majority element is the element that appearsmore than⌊ n/2 ⌋times.You may assume that the array is non-empty and the majority element alwa...原创 2019-08-21 19:48:35 · 104 阅读 · 0 评论 -
Leetcode - 462. Minimum Moves to Equal Array Elements II (相遇问题)
Given anon-emptyinteger array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by ...原创 2019-08-21 19:35:01 · 106 阅读 · 0 评论 -
Leetcode - 504. Base 7 (位运算)
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note:The input will be in range of [-1e7, 1e7].def conver...原创 2019-08-21 19:19:42 · 119 阅读 · 0 评论 -
Leetcode - 260. Single Number III (位运算)
Given an array of numbersnums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.Example:Input: [1,2,1,...原创 2019-08-21 10:09:49 · 89 阅读 · 0 评论 -
Leetcode - 378. Kth Smallest Element in a Sorted Matrix (数组和矩阵)
Given anxnmatrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not t...原创 2019-08-21 09:25:52 · 141 阅读 · 0 评论 -
Leetcode - 409. Longest Palindrome(字符串)
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example"Aa"is not consi...原创 2019-08-21 09:01:50 · 85 阅读 · 0 评论 -
Leetcode - 232. 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 element. em...原创 2019-08-21 08:45:07 · 92 阅读 · 0 评论 -
Leetcode - 242. Valid Anagram (字符串)
Given two stringssandt, write a function to determine iftis an anagram ofs.Example 1:Input: s = "anagram", t = "nagaram"Output: trueExample 2:Input: s = "rat", t = "car"Output: fal...原创 2019-08-21 08:23:44 · 80 阅读 · 0 评论 -
Leetcode - 1. Two Sum (哈希表)
Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesame...原创 2019-08-21 08:18:51 · 101 阅读 · 0 评论 -
Leetcode - 160. Intersection of Two Linked 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:begin to intersect at node c1.Example 1:Input: ...原创 2019-08-21 08:11:10 · 133 阅读 · 0 评论 -
Leetcode - 241. Different Ways to Add Parentheses (分治)
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+,-and*.Example 1:In...原创 2019-08-20 22:19:28 · 102 阅读 · 0 评论 -
Leetcode - 69. Sqrt(x) (二分)
Implementint sqrt(int x).Compute and return the square root ofx, wherexis guaranteed to be a non-negative integer.Since the return typeis an integer, the decimal digits are truncated and only...原创 2019-08-20 22:05:32 · 65 阅读 · 0 评论 -
Leetcode - 455. Assign Cookies (贪心算法)
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a coo...原创 2019-08-20 21:52:42 · 85 阅读 · 0 评论 -
Leetcode-75. Sort Colors (荷兰国旗问题)
Given an array withnobjects colored red, white or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the in...原创 2019-08-20 21:45:17 · 106 阅读 · 0 评论 -
Leetcode - 347. Top K Frequent Elements(堆排序)
Given a non-empty array of integers, return thekmost frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]Note:You...原创 2019-08-20 21:30:26 · 122 阅读 · 0 评论 -
Leetcode-215. Kth Largest Element in an Array(快排)
Find thekth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,5,6,4] and k = 2Output: 5E...原创 2019-08-20 21:22:46 · 134 阅读 · 0 评论 -
Leetcode - 167. Two Sum II - Input array is sorted(双指针)
Given an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers ...原创 2019-08-20 20:59:25 · 75 阅读 · 0 评论 -
在有序旋转数组中找到最小值
题目 有序数组arr可能经过一次旋转处理,也可能没有,且arr可能存在重复的数。例如,有序数组[1,2,3,4,5,6,7],可以旋转处理成[4,5,6,7,1,2,3]等。给定一个可能旋转过的有序数组arr,返回arr中的最小值。基本思路 尽可能的利用二分查找,但是最坏情况仍然无法避免O(N)的时间复杂度。首先需要知道,如果一个有序数组经过旋转后,最小的值一定是数组中降序的那个位...原创 2019-08-20 18:05:58 · 717 阅读 · 0 评论 -
累加出整个范围所有的数最少还需要几个数
题目:给定一个有序的正数数组arr和一个正数range,如果可以自由选择arr中的数字,想累加得到1~range范围上所有的数,返回arr最少还缺几个数举例:arr = [1,2,3,7] range = 15 1~15还缺14 返回1arr = [1,5,7] range = 15 1~15还缺2和4 返回2def needMins(arr,range_): ra...原创 2019-08-20 17:34:27 · 423 阅读 · 0 评论 -
正数数组的最小不可组成和
题目 给定一个正数数组arr,其中所有的值都是整数,以下是最小不可组成和的概念:把arr每个子集内的所有元素加起来会出现很多值,其中最小的记为min,最大的记为max。在区间[min, max]上,如果有数不可以被arr某一个子集相加得到,那么其中最小的那个数就是arr的最小不可组成和。在区间[min, max]上,如果所有的数都可以被arr的某一个子集相加得到,那么max + 1是arr的...原创 2019-08-20 11:32:16 · 232 阅读 · 0 评论 -
从5随机到7随机及其扩展
题目 给定一个等概率产生1~5的随机函数 rand1To5如下:def rand1To5(): import random return int(random.random()*5) + 1 除此之外,不使用任何额外的随机机制,请用rand1To5实现等概率随机产生1~7的随机函数rand1To7基本思路: 1、rand1To5() 等概率产生...原创 2019-08-18 08:28:00 · 365 阅读 · 0 评论 -
判断一个数是否是回文数
题目: 定义回文数的概念如下: 1. 如果一个非负数左右完全对应,则该数是回文数,例如:121,22等 2. 如果一个负数的绝对值左右完全对应,也是回文数,例如:-121,-22等 给定一个32位整数num,判断num是否是回文数。基本思路 具体过程如下: 1、假设判断的数字为非负整数n,先生成变量help,开始时help = 1 2、用help不断地...原创 2019-08-17 18:57:01 · 1655 阅读 · 0 评论 -
从N个数中等概率打印M个数
题目:给定一个长度为N且没有重复元素的数组arr和一个整数m,实现函数等概率随机打印arr中的M个数。要求: 相同的数不要重复打印 时间复杂度O(M),空间复杂度O(1) 可以改变arr数组基本思路 具体过程如下: 1、在arr[0…N-1]中随机得到一个位置a,然后打印arr[a]。 2、把arr[a]和arr[N-1]交换。...原创 2019-08-17 18:25:46 · 174 阅读 · 0 评论 -
调整[0,x)区间上出现的概率
题目 假设函数random()等概率随机返回一个在[0, 1)范围上的数,那么我们知道,在[0, x)区间上的数出现的概率为x(0<x≤10<x≤1)。给定一个大于0的整数k,并且可以使用random()函数,请实现一个函数依然返回[0,1)范围上的数,但是在[0, x)区间上的数出现的概率为xkxk(0<x≤10<x≤1)。基本思路 调用k次random(...原创 2019-08-17 15:46:02 · 300 阅读 · 0 评论 -
能否完美拼成矩形
题目:给定一个N行4列的二维数组matrix,表示N个每条边不是平行于X轴就是平行于Y轴的矩形,想知道所有的矩形能否组成一个大的完美矩形。完美矩形是指拼出的整体图案是矩形,既不缺任何块,也没有重合的部分。思路:1、每一个小矩形的面积累加起来必须是等于大矩形的面积 2、除大矩形的四个顶点只出现一次之外,其它任何小矩形的顶点都必须出现偶数次。def isRectangleCover(mat...原创 2019-08-17 11:07:17 · 851 阅读 · 0 评论 -
判断一个点是否在三角形内部
题目:在二维坐标系中,所有的值都是double型,那么一个三角形可以由三个点来代表,给定三个点代表的三角形,再给定一个点(x, y),判断(x, y)是否在三角形中基本思路:如果一个点O在三角形的内部,那么从三角形的一个点出发,逆时针走过所有边的过程中,点O始终在走过边的左边。如果点O在外侧,则不满足这一条件。 如果要逆时针走过一遍三角形,那么三个点的位置是重要的,假设输入的三个点依...原创 2019-08-17 10:23:45 · 2377 阅读 · 0 评论