自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(221)
  • 资源 (2)
  • 收藏
  • 关注

原创 leetcode【455,135,435,605,452,122,406,665】【贪心类小合集】【c++版本】

这两天刷了几道贪心算法的题目,稍微记录一下,思路后面在补充。 455.Assign Cookies class Solution { public: int findContentChildren(vector<int>& g, vector<int>& s) { if (s.size() == 0) { return 0; } sort(g.begin(), g.end()); .

2020-12-16 10:38:37 156

原创 leetcode【210】【Depth-first Search】Course Schedule II【c++版本】

问题描述: There are a total ofncourses you have to take labelled from0ton - 1. Some courses may haveprerequisites, for example, ifprerequisites[i] = [ai, bi]this means you must take the coursebibefore the courseai. Given the total number of cours...

2020-12-14 13:49:01 201

原创 leetcode【207】【Depth-first Search】Course Schedule【c++版本】

Hello,各位,我又回来了。做了一学期废物,这赶紧回来找找感觉了。 问题描述: There are a total ofnumCoursescourses you have to take, labeled from0tonumCourses-1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a...

2020-12-14 11:25:07 138

原创 leetcode【345】【tag String】Reverse Vowels of a String【c++版本,beats 99%,多种解法】

问题描述: Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Input: "hello" Output: "holle" Example 2: Input: "leetcode" Output: "leotcede" Note: The vowels does not include the letter "y". 源码: 方案一: 用一

2020-11-14 17:13:08 94

原创 leetcode【344】【tag String】Reverse String【c++版本,beats 80%,多种解法】

问题描述: Write a function that reverses a string. The input string is given as an array of characterschar[]. Do not allocate extra space for another array, you must do this bymodifying the input arrayin-placewith O(1) extra memory. You may assume all t...

2020-11-14 16:27:04 71

原创 leetcode【336】【tag String】Palindrome Pairs 【c++,beats 70%】

问题描述: Given a list ofuniquewords, return all the pairs of thedistinctindices(i, j)in the given list, so that the concatenation of the two wordswords[i] + words[j]is a palindrome. Example 1: Input: words = ["abcd","dcba","lls","s","sssll"] Ou...

2020-11-13 19:33:26 95

原创 leetcode【316】【tag String】Remove Duplicate Letters【c++版本】

问题描述: Given a strings, remove duplicate letters so that every letter appears once and only once. You must make sure your result isthe smallest in lexicographical orderamong all possible results. Note:This question is the same as 1081:https://leetcod...

2020-11-09 15:33:25 97

原创 leetcode【222】【tag Tree】Count Complete Tree Nodes【c++版本,多种解法】

问题描述: Share Given acompletebinary tree, count the number of nodes. Note: Definition of a complete binary tree fromWikipedia: In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are a...

2020-07-02 15:29:37 297

原创 leetcode【231】【tag Math】Power of Two【c++版本,多种解法,时间100%】

问题描述: 源码: 方法1: 取n的log(n)/log(2),如果再做2的幂次方后等于本身,就说明是2的幂次方。因为如果不是2的幂次方,则结果等于小数,无法复原。 时间100%,空间差点。 class Solution { public: bool isPowerOfTwo(int n) { if (n==0) return false; float m = log(n) / log(2); if (pow(2, m) == n)

2020-07-02 13:41:36 166

原创 leetcode【204】【tag Math】Count Primes【c++版本,改进的素数表法】

问题描述: Count the number of prime numbers less than a non-negative number,n. Example: Input: 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. 源码: 改进的素数表法。用prime存储当前所有的素数,用visit表示当前的数字是否为素数,true表示是素数,false表示是合数。 点.

2020-06-30 10:07:42 101

原创 leetcode【202】【tag Math】Happy Number【c++版本,时间100%】

问题描述: Write an algorithm to determine if a numbernis "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the ..

2020-06-29 11:20:19 144

原创 Key Spotting 小总结【关键词搜索】【大部分源于interspeech和ICASSP】

最近转了方向,就看了一些NLP方面的文章,这里做的小总结 目录 A survey on structured discriminative spoken keyword spotting SMALL-FOOTPRINT KEYWORD SPOTTING USING DEEP NEURAL NETWORKS Convolutional Neural Networks for Small-footprint Keyword Spotting Query-by-example keyword spott

2020-06-22 14:41:53 1741 1

原创 leetcode【312】Burst Balloons【c++版本,时间81%】

问题描述: Givennballoons, indexed from0ton-1. Each balloon is painted with a number on it represented by arraynums. You are asked to burst all the balloons. If the you burst ballooniyou will getnums[left] * nums[i] * nums[right]coins. Hereleftand...

2020-06-19 21:07:07 181

原创 leetcode【309】Best Time to Buy and Sell Stock with Cooldown【c++版本,时间100%,空间O(1)】

问题描述: 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 and sell one share of the stock multiple times) w...

2020-06-19 20:53:12 117

原创 leetcode【303、304】【tag DP】Range Sum Query - Immutable、Range Sum Query 2D - Immutable【c++版本,动态规划时间97%】

问题描述: 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) -> 1 sumRange(2, 5) -> -1 sumRange(0, 5) -> -3 Note: You may assume t...

2020-06-16 14:02:41 153

原创 leetcode【300】【tag DP Binary Search】Longest Increasing Subsequence【c++版本,时间95%,二分查找】

问题描述: Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. Note: There may

2020-06-16 13:56:51 142

原创 leetcode【213】【tag DP】House Robber II【c++版本,时间O(n),空间O(1)】

问题描述: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place arearranged in a circle.That means the first house is the neighbor of the last one. Meanwhile, adjacent..

2020-06-15 15:48:20 157

原创 leetcode【289】【tag Array】Game of Life【c++版本,时间100%,空间O(1)】

问题描述: According to theWikipedia's article: "TheGame of Life, also known simply asLife, is a cellular automaton devised by the British mathematician John Horton Conway in 1970." Given aboardwithmbyncells, each cell has an initial statelive(1) o...

2020-06-14 21:33:27 113

原创 leetcode【287】【tag Array Two pointers】Find the Duplicate Number【c++版本,时间89%,两种解法】

问题描述: Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one. Example 1: Input: [1,3,4...

2020-06-14 14:18:55 102

原创 leetcode【238】【tag Array】Product of Array Except Self【c++版本,多种解法】

问题描述: 源码: 我翻了翻solution区(非会员难得看到solution)。看到一种更简单的方法。先用result[i]存储前 i-1 个元素的值。然后用R存储右边的值。从右向左遍历,保证求最后一个元素的时候R为1,倒数第二个元素的时候R为nums[n-1],倒数第三个元素的时候R为nums[n-1] * nums[n-2] ...... class Solution { public: vector<int> productExceptSelf(vector<.

2020-06-10 10:18:19 119

原创 leetcode【229】【tag Array】Majority Element II【c++版本,时间O(n)超越76%】

源码:

2020-06-10 09:14:40 95

原创 leetcode【228】【tag Array】Summary Ranges【c++版本,时间100%,有截图】

问题描述: Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: [0,1,2,4,5,7] Output: ["0->2","4->5","7"] Explanation: 0,1,2 form a continuous range;4,5 form a continuous range. Example 2: Input: .

2020-06-06 16:31:11 101

原创 leetcode【217、218】【tag Array】Contains Duplicate I / II【c++版本,hash用法】

问题描述(217): Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Example 1: Input: [1,2,3,1] O

2020-06-06 14:03:32 63

原创 leetcode【216】【tag Array Backtracking】Combination Sum III【c++版本,DFS,时间空间100%】

问题描述: Find all possible combinations ofknumbers that add up to a numbern, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Note: All numbers will be positive integers. The solution set must not ...

2020-06-03 15:20:16 100

原创 leetcode【209】【tag Array】Minimum Size Subarray Sum【c++版本,时间从O(n^2)到O(n)】

问题描述: Given an array ofnpositive integers and a positive integers, find the minimal length of acontiguoussubarray of which the sum ≥s. If there isn't one, return 0 instead. Example: Input: s = 7, nums = [2,3,1,2,4,3] Output: 2 Explanation: the s...

2020-06-02 15:14:49 139

原创 leetcode【172】【tag Math】Factorial Trailing Zeroes【c++版本,时间空间100%】

源码: 这题直接乘铁不行,万一n太大咋办。于是我就想统计2和5得个数。结果还是超时了,最后两个没过。 class Solution { public: int trailingZeroes(int n) { int result = 0; int count_2=0, count_5=0; for(int i=2; i<=n; i++){ int tmp = i; while(tmp...

2020-06-02 13:18:44 107

原创 leetcode【168、171】【tag Math】Excel Sheet Column Title、Excel Sheet Column Number【c++版本,时间空间100%】

问题描述: Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB ... Example 1: Input: 1 Output: "A

2020-06-01 09:26:42 138

原创 leetcode【87】【tag string】Repeated DNA Sequences【c++版本,时间92%,空间100%,位运算,hash表】

问题描述: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Write a function to find all the 10-letter-long sequen

2020-05-26 14:52:00 123

原创 leetcode【165】【tag string】Compare Version Numbers【c++版本,时间空间100%】

问题描述: Compare two version numbersversion1andversion2. Ifversion1>version2return1;ifversion1<version2return-1;otherwise return0. You may assume that the version strings are non-empty and contain only digits and the.character. The....

2020-05-25 12:48:53 132

原创 leetcode【200】【tag DFS】Number of Islands【c++版本,递归与非递归】

问题描述: 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 all four edges of the grid are all surrounded by..

2020-05-20 10:03:19 151

原创 leetcode【151】【tag String】Reverse Words in a String【c++版本,多种解法,翻转法和巧妙字符串流】

问题描述: Given an input string, reverse the string word by word. Example 1: Input: "the sky is blue" Output:"blue is sky the" Example 2: Input: " hello world! " Output:"world! hello" Explanation: Your reversed string should not contain leading or ...

2020-05-20 09:22:25 102

原创 leetcode【199】【tag Tree】Binary Tree Right Side View【c++版本,层次遍历,DFS两种方法】

问题描述: 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] Explanation: 1 <--- / \ 2 ...

2020-05-19 14:19:37 115

原创 leetcode【173】Binary Search Tree Iterator【c++版本,多种解法】

问题描述: Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Callingnext()will return the next smallest number in the BST. Example: BSTIterator iterator = new BSTIterator(root); ite...

2020-05-18 11:58:58 102

原创 leetcode【198】【tag DP】House Robber【c++版本,动态规划,时间空间O(n)均100%】

问题描述: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected andit will auto.

2020-05-18 11:18:53 250

原创 leetcode【188】【tag DP】Best Time to Buy and Sell Stock IV【c++版本,时间O(nk)空间O(k)】

问题描述: Say you have an array for which thei-thelement is the price of a given stock on dayi. Design an algorithm to find the maximum profit. You may complete at mostktransactions. Note: You may not engage in multiple transactions at the same time (i...

2020-05-17 13:53:11 110

原创 leetcode【174】【tag DP】Dungeon Game【c++版本,动态规划】

问题描述: The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his w

2020-05-17 12:57:38 111

原创 leetcode【189】Rotate Array【c++,时间99%O(n),空间O(1),多种解法】

问题描述: Given an array, rotate the array to the right byksteps, wherekis non-negative. Follow up: Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. Could you do it in-place with O(1) extra space? ...

2020-05-14 15:12:29 117

原创 leetcode【169】Majority Element【c++版本,时间87%,数组特点法】

源码: 《剑指offer》的第39题,欢迎读者查看剑指offer总纲。 如果我们回到题目本身仔细分析,如果这个数组已经排序,那么排序之后位于数组中间的数字一定就是那个出现次数超过数组长度一半的数字。也就是说,这个数字是统计学上的中位数。我们有成熟的算法能够在O(n)时间内找到数组中任意第k大的数字(快速排序)。 遗憾的是,编完后,超时了,最后一个案例超时。 class Solution { public: int partition(vector<int>& ...

2020-05-14 12:14:03 120

原创 leetcode【167】Two Sum II - Input array is sorted【双指针法,时间O(n),空间O(1)】

问题描述: 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 such that they add up to the target, where index1.

2020-05-14 09:42:34 132

原创 leetcode【162】【tag array】Find Peak Element【c++版本,时间96%,递归和非递归】

问题描述: A peak element is an element that is greater than its neighbors. Given an input arraynums, wherenums[i] ≠ nums[i+1], find a peak element and return its index. The array may contain multiple peaks, in that case return the index to any one of the ..

2020-05-13 13:27:45 99

数学建模算法大全

该资源中包含了一些重要的数学建模算法

2017-06-08

汇编语言推荐使用的环境

汇编资源推荐使用的环境由于教学

2017-06-08

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除