![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
没事多喝白开水
这个作者很懒,什么都没留下…
展开
-
Leetcode101. Symmetric Tree
给定一个二叉树,检查它是否是镜像对称的。例如,二叉树 [1,2,2,3,4,4,3] 是对称的。1/ 2 2/ \ / 3 4 4 3但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:1/ 2 2\ 3 3说明:如果你可以运用递归和迭代两种方法解决这个问题,会很加分。来源:力扣(LeetCode)链接:https://...原创 2019-08-17 03:18:01 · 151 阅读 · 0 评论 -
Leetcode338. Counting Bits
Given a non negative integer number num. For every numbers i in therange 0 ≤ i ≤ num calculate the number of 1’s in their binaryrepresentation and return them as an array.Example 1:Input: 2 Outpu...原创 2019-08-05 20:28:37 · 78 阅读 · 0 评论 -
Leetcode322. Coin Change
You are given coins of different denominations and a total amount ofmoney amount. Write a function to compute the fewest number of coinsthat you need to make up that amount. If that amount of money...原创 2019-08-05 19:47:38 · 80 阅读 · 0 评论 -
Leetcode309. Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of agiven stock on day i.Design an algorithm to find the maximum profit. You may complete asmany transactions as you like (ie, buy one ...原创 2019-08-05 17:47:19 · 75 阅读 · 0 评论 -
Leetcode300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longestincreasing subsequence.Example:Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longestincreasing subsequence is [2,3,7,101]...原创 2019-08-05 16:40:54 · 78 阅读 · 0 评论 -
Leetcode279. Perfect Squares
Given a positive integer n, find the least number of perfect squarenumbers (for example, 1, 4, 9, 16, …) which sum to n.Example 1:Input: n = 12 Output: 3 Explanation: 12 = 4 + 4 + 4. Example 2:I...原创 2019-08-05 15:31:11 · 61 阅读 · 0 评论 -
[转]Leetcode刷题指南和top100题目
https://blog.csdn.net/lingpy/article/details/88085446转载 2019-07-26 20:52:06 · 273 阅读 · 0 评论 -
Leetcode221. Maximal Square
Given a 2D binary matrix filled with 0’s and 1’s, find the largestsquare containing only 1’s and return its area.Example:Input:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Output: 4动态规划20msclass ...原创 2019-08-04 19:17:56 · 86 阅读 · 0 评论 -
Leetcode198. House Robber
You are a professional robber planning to rob houses along a street.Each house has a certain amount of money stashed, the only constraintstopping you from robbing each of them is that adjacent hous...原创 2019-08-04 18:10:16 · 68 阅读 · 0 评论 -
Leetcod91. Decode Ways
A message containing letters from A-Z is being encoded to numbersusing the following mapping:‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given a non-empty string containingonly digits, determine the to...原创 2019-07-31 17:38:54 · 73 阅读 · 0 评论 -
Leetcode152. Maximum Product Subarray
Given an integer array nums, find the contiguous subarray within anarray (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4] Output: 6 Explanation: [2,3] has...原创 2019-08-04 17:34:27 · 75 阅读 · 0 评论 -
Leetcode139. Word Break
Given a non-empty string s and a dictionary wordDict containing a listof non-empty words, determine if s can be segmented into aspace-separated sequence of one or more dictionary words.Note:The s...原创 2019-08-04 16:09:39 · 57 阅读 · 0 评论 -
Leetcode121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of agiven stock on day i.If you were only permitted to complete at most one transaction (i.e.,buy one and sell one share of the stock),...原创 2019-07-31 14:12:59 · 61 阅读 · 0 评论 -
Leetcode96. Unique Binary Search Trees
Given n, how many structurally unique BST’s (binary search trees) thatstore values 1 … n?Example:Input: 3 Output: 5 Explanation: Given n = 3, there are a total of 5unique BST’s:1 3 3...原创 2019-07-31 13:11:40 · 54 阅读 · 0 评论 -
C++关键字
注:上表中为C++98/03中的63个关键字,其中红色标注为C语言中的32个关键字。C++11中有73个关键字,新增加的10个为:alignas、alignof、char16_t、char32_t、constexpr、decltype、noexpect、nullptr、static_assert、thread_local以下是对部分关键字的解释:1、asm_asm是一个语句的分隔符。不能单独...转载 2019-07-25 19:27:52 · 124 阅读 · 0 评论 -
Leetcode70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct wayscan you climb to the top?Note: Given n will be a positive ...原创 2019-07-30 21:54:00 · 56 阅读 · 0 评论 -
Leetcode647. Palindromic Substrings
Given a string, your task is to count how many palindromic substringsin this string.The substrings with different start indexes or end indexes are countedas different substrings even they consist ...原创 2019-08-05 21:22:38 · 61 阅读 · 0 评论 -
Leetcode 5. 最长回文子串
给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。示例 1:输入: “babad” 输出: “bab” 注意: “aba” 也是一个有效答案。 示例 2:输入: “cbbd” 输出: “bb”来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/longest-palindromic-substrin...原创 2019-07-28 14:39:55 · 68 阅读 · 0 评论 -
Leetcode494. Target Sum
You are given a list of non-negative integers, a1, a2, …, an, and atarget, S. Now you have 2 symbols + and -. For each integer, youshould choose one from + and - as its new symbol.Find out how man...原创 2019-08-05 23:46:29 · 88 阅读 · 0 评论 -
Leetcode509. Fibonacci Number
斐波那契数,通常用 F(n) 表示,形成的序列称为斐波那契数列。该数列由 0 和 1 开始,后面的每一项数字都是前面两项数字的和。也就是:F(0) = 0, F(1) = 1 F(N) = F(N - 1) + F(N - 2), 其中 N > 1. 给定 N,计算F(N)。示例 1:输入:2 输出:1 解释:F(2) = F(1) + F(0) = 1 + 0 = 1. 示例...原创 2019-08-17 00:51:26 · 149 阅读 · 0 评论 -
Leetcode451. Sort Characters By Frequency
给定一个字符串,请将字符串里的字符按照出现的频率降序排列。示例 1:输入: “tree”输出: “eert”解释: 'e’出现两次,'r’和’t’都只出现一次。 因此’e’必须出现在’r’和’t’之前。此外,"eetr"也是一个有效的答案。 示例2:输入: “cccaaa”输出: “cccaaa”解释: 'c’和’a’都出现三次。此外,"aaaccc"也是有效的答案。 注意"ca...原创 2019-08-13 02:05:45 · 125 阅读 · 0 评论 -
Leetcode75. Sort Colors
给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。此题中,我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。注意: 不能使用代码库中的排序函数来解决这道题。示例:输入: [2,0,2,1,1,0] 输出: [0,0,1,1,2,2] 进阶:一个直观的解决方案是使用计数排序的两趟扫描算法。 首先,迭代...原创 2019-08-13 02:01:46 · 90 阅读 · 0 评论 -
Leetcode 347. 前K个高频元素 C++
给定一个非空的整数数组,返回其中出现频率前 k 高的元素。示例 1:输入: nums = [1,1,1,2,2,3], k = 2 输出: [1,2] 示例 2:输入: nums = [1], k = 1 输出: [1] 说明:你可以假设给定的 k 总是合理的,且 1 ≤ k ≤ 数组中不相同的元素的个数。 你的算法的时间复杂度必须优于 O(n log n) , n是数组的大小。来源...原创 2019-06-21 16:47:51 · 784 阅读 · 0 评论 -
快手笔试题Leetcode165
比较两个版本号 version1 和 version2。如果 version1 > version2 返回 1,如果 version1 < version2 返回 -1, 除此之外返回 0。你可以假设版本字符串非空,并且只包含数字和 . 字符。. 字符不代表小数点,而是用于分隔数字序列。例如,2.5 不是“两个半”,也不是“差一半到三”,而是第二版中的第五个小版本。你可以假...原创 2019-08-25 19:13:56 · 489 阅读 · 0 评论 -
Leetcode215. Kth Largest Element in an Array
在未排序的数组中找到第 k 个最大的元素。请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。示例 1:输入: [3,2,1,5,6,4] 和 k = 2 输出: 5 示例 2:输入: [3,2,3,1,2,4,5,5,6] 和 k = 4 输出: 4 说明:你可以假设 k 总是有效的,且 1 ≤ k ≤ 数组的长度。来源:力扣(LeetCode)链接:...原创 2019-08-12 03:13:33 · 91 阅读 · 0 评论 -
Leetcode524. Longest Word in Dictionary through Deleting
给定一个字符串和一个字符串字典,找到字典里面最长的字符串,该字符串可以通过删除给定字符串的某些字符来得到。如果答案不止一个,返回长度最长且字典顺序最小的字符串。如果答案不存在,则返回空字符串。示例 1:输入: s = “abpcplea”, d = [“ale”,“apple”,“monkey”,“plea”]输出: “apple” 示例 2:输入: s = “abpcplea”, d...原创 2019-08-12 02:01:44 · 119 阅读 · 0 评论 -
Leetcode141. Linked List Cycle
给定一个链表,判断链表中是否有环。为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos 是-1,则在该链表中没有环。示例 1:输入:head = [3,2,0,-4], pos = 1 输出:true 解释:链表中有一个环,其尾部连接到第二个节点。 示例 2:输入:head = [1,2], pos = 0 输出:true ...原创 2019-08-12 00:52:16 · 76 阅读 · 0 评论 -
Leetcode88. Merge Sorted Array
给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组。说明:初始化 nums1 和 nums2 的元素数量分别为 m 和 n。 你可以假设 nums1 有足够的空间(空间大小大于或等于 m +n)来保存 nums2 中的元素。 示例:输入: nums1 = [1,2,3,0,0,0], m = 3 nums2 = [2...原创 2019-08-12 00:28:56 · 76 阅读 · 0 评论 -
Leetcode680. Valid Palindrome II
Given a non-empty string s, you may delete at most one character.Judge whether you can make it a palindrome.Example 1: Input: “aba” Output: True Example 2: Input: “abca” Output:True Explanation: Y...原创 2019-08-11 02:31:26 · 82 阅读 · 0 评论 -
Leetcode345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only thevowels of a string.Example 1:Input: “hello” Output: “holle” Example 2:Input: “leetcode” Output: “leotcede” Note: The vowels does ...原创 2019-08-11 01:28:51 · 112 阅读 · 0 评论 -
Leetcode633. Sum of Square Numbers
Given a non-negative integer c, your task is to decide whetherthere’re two integers a and b such that a2 + b2 = c.Example 1:Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5Example 2:Input: 3...原创 2019-08-11 01:11:43 · 87 阅读 · 0 评论 -
Leetcode167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted 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-11 00:45:52 · 72 阅读 · 0 评论 -
Leetcode127. Word Ladder
给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord的最短转换序列的长度。转换需遵循如下规则:每次转换只能改变一个字母。 转换过程中的中间单词必须是字典中的单词。 说明:如果不存在这样的转换序列,返回 0。 所有单词具有相同的长度。 所有单词只由小写字母组成。 字典中不存在重复的单词。 你可以假设beginWord 和 endW...原创 2019-08-15 04:13:24 · 119 阅读 · 0 评论 -
Leetcode92. Reverse Linked List II
Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4 Output: 1->4->3->2->5->...原创 2019-07-30 21:33:35 · 66 阅读 · 0 评论 -
通过 C++ Primer 重学习 C++(摘自知乎)
作者:知乎用户链接:https://www.zhihu.com/question/32087709/answer/54936403来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。个人经验,C++ primer 第一次可以跳着看。关键是要尽快用起来,在使用中熟练,而不是在细节中迷失。以C++ Primer第五版为例,第一遍读的时候:Part1也就是前七章...转载 2019-07-21 21:54:05 · 255 阅读 · 0 评论 -
常见排序算法的C++实现&&亿级排序效率测试
选择排序插入排序冒泡排序希尔排序归并排序快速排序及优化对于100000000/一亿个int型数组排序简单测试排序时间,目前测试结果Shell Sort : 40.211 sQuick Sort : 39.22 s希尔排序与快速排序两者不相上下对于500000000/一亿个int型数组排序简单测试排序时间,目前测试结果Shell Sort : 275.252 s...原创 2019-07-15 22:24:30 · 602 阅读 · 0 评论 -
记录C++一些编程bug的解决
1、copy的使用1>f:\visual studio\vc\include\xutility(2230): error C4996:‘std::_Copy_impl’: Function call with parameters that may be unsafe -this call relies on the caller to check that the passed v...原创 2019-07-15 02:38:53 · 893 阅读 · 0 评论 -
387. 字符串中的第一个唯一字符
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。案例:s = “leetcode” 返回 0.s = “loveleetcode”, 返回 2.注意事项:您可以假定该字符串只包含小写字母。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/first-unique-character-in-a-s...原创 2019-07-14 19:48:35 · 173 阅读 · 0 评论 -
C++实现简单的红黑树
红黑树简单介绍红黑树是带有颜色属性的自平衡二叉查找树。对红黑树的操作在最坏情形下花费O(logN)时间,红黑树的高度最多是2log(N+1)。红黑树是具有下列着色性质的二叉查找树:1、每一个节点或者着成红色,或者着成黑色;2、根是黑色的;3、如果一个节点是红色的,那么它的子节点必须是黑色的;4、从一个节点到一个NULL指针的每一条路径必须包含相同数目的黑色节点。作者:下午茶609 ...原创 2019-07-14 19:33:03 · 242 阅读 · 0 评论 -
C++实现简单AVL树与二分搜索树
主要包括添加、删除、遍历等功能#define _CRK_SECURE_NO_WARNINGS#include <iostream>#include <fstream>#include <sstream>#include <vector>using namespace std;int max(int a, int b) { retur...原创 2019-07-14 17:00:18 · 273 阅读 · 0 评论