![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
简单题
C++练习
JIngles123
生命不息,奋斗不止
展开
-
力扣-1768题 交替合并字符串(C++)- 双指针
【代码】力扣-1768题 交替合并字符串(C++)- 双指针。原创 2023-06-06 20:40:00 · 111 阅读 · 0 评论 -
力扣-724题 寻找数组的中心下标(C++)- 双指针
【代码】力扣-724题 寻找数组的中心下标(C++)- 双指针。原创 2022-10-10 20:54:24 · 317 阅读 · 0 评论 -
力扣-1480题 一维数组的动态和(C++)
【代码】力扣-1480题 一维数组的动态和(C++)原创 2022-10-10 20:11:35 · 309 阅读 · 0 评论 -
力扣-674题 最长连续递增序列(C++)- 动态规划
代码】力扣-674题 最长连续递增序列(C++)- 动态规划。原创 2022-08-12 11:57:27 · 131 阅读 · 0 评论 -
力扣-392题 判断子序列(C++)- 动态规划
代码】力扣-392题 判断子序列(C++)- 动态规划。原创 2022-08-08 17:22:32 · 191 阅读 · 0 评论 -
力扣-461题 汉明距离(C++)- 位运算
代码】力扣-461题汉明距离(C++)-位运算。原创 2022-07-24 17:37:21 · 115 阅读 · 0 评论 -
力扣-338题 比特位计数(C++)- 位运算
代码】力扣-338题比特位计数(C++)-位运算。原创 2022-07-24 17:09:32 · 105 阅读 · 0 评论 -
力扣-剑指Offer 57-II题 和为s的连续正数序列(C++)- 双指针
题目链接:https://leetcode.cn/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/题目如下:原创 2022-07-05 16:19:10 · 105 阅读 · 0 评论 -
力扣 - 746题 使用最小花费爬楼梯 (C++) - dp
题目链接:https://leetcode.cn/problems/min-cost-climbing-stairs/题目如下:原创 2022-06-10 18:28:11 · 161 阅读 · 0 评论 -
力扣-543题 二叉树的直径(C++)- dfs
题目链接:https://leetcode-cn.com/problems/diameter-of-binary-tree/题目如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {}原创 2022-05-09 01:23:27 · 211 阅读 · 0 评论 -
力扣-2190题 数组中紧跟key之后出现最频繁的数字(C++)- 哈希
题目链接:https://leetcode-cn.com/problems/most-frequent-number-following-key-in-an-array/题目如下:class Solution {public: int mostFrequent(vector<int>& nums, int key) { map<int,int> umap; bool flag=false; for(int i原创 2022-05-03 10:59:03 · 531 阅读 · 0 评论 -
力扣-733题 图像渲染(C++)- BFS
题目链接:https://leetcode-cn.com/problems/flood-fill/题目如下:class Solution {public: vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int newColor) { int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};原创 2022-04-27 11:28:47 · 148 阅读 · 0 评论 -
力扣-面试题 08.10题 颜色填充(C++)- BFS
题目链接:https://leetcode-cn.com/problems/color-fill-lcci/题目如下:class Solution {public: vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int newColor) { int m=image.size(); if(m==0) re原创 2022-04-27 11:07:06 · 453 阅读 · 0 评论 -
力扣-1672题 最富有客户的资产总量(C++)- accumulate函数
题目链接:https://leetcode-cn.com/problems/richest-customer-wealth/题目如下:class Solution {public: int maximumWealth(vector<vector<int>>& accounts) { //accumulate函数可以求和、练乘、求string拼接,包含的头文件为#include<numeric> int res=0;原创 2022-04-14 10:35:17 · 535 阅读 · 0 评论 -
力扣-263题 丑数(C++)- 递归
题目链接:https://leetcode-cn.com/problems/ugly-number/题目如下:class Solution {public: bool isUgly(int n) { if(n<=0) return false; if(n%2==0) return isUgly(n/2); if(n%3==0) return isUgly(n/3); if(n%5==0) return isUgly(n/原创 2022-04-13 22:57:26 · 595 阅读 · 0 评论 -
力扣-804题 唯一摩尔斯密码词(C++)- unordered_map
题目链接:https://leetcode-cn.com/problems/unique-morse-code-words/题目如下:class Solution {public: int uniqueMorseRepresentations(vector<string>& words) { string str[]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",原创 2022-04-10 15:05:05 · 172 阅读 · 0 评论 -
力扣-面试题17.12题 BiNode(C++)- dfs
题目链接:https://leetcode-cn.com/problems/binode-lcci/题目如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cl原创 2022-04-09 22:43:18 · 535 阅读 · 0 评论 -
力扣-108题 将有序数组转换为二叉搜索树(C++)- dfs
题目链接:https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/题目如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullpt原创 2022-04-09 02:42:06 · 432 阅读 · 0 评论 -
力扣-501题 二叉搜索树中的众数(C++)- dfs
题目链接:https://leetcode-cn.com/problems/find-mode-in-binary-search-tree/题目如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nu原创 2022-04-07 20:30:12 · 423 阅读 · 0 评论 -
力扣-783题 二叉搜索树节点最小距离(C++)- dfs
题目链接:https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/题目如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right原创 2022-04-06 23:10:36 · 330 阅读 · 0 评论 -
力扣-530题 二叉搜索树的最小绝对差(C++)- dfs
题目链接:https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/题目如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right原创 2022-04-06 23:01:08 · 506 阅读 · 0 评论 -
力扣-剑指Offer 68-I题 二叉搜索树的最近公共祖先(C++)- 递归
题目链接:https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-zui-jin-gong-gong-zu-xian-lcof/题目如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x原创 2022-04-03 00:13:02 · 82 阅读 · 0 评论 -
力扣-1539题 第k个缺失的正整数(C++)- 枚举
题目链接:https://leetcode-cn.com/problems/kth-missing-positive-number/题目如下:class Solution {public: int findKthPositive(vector<int>& arr, int k) { int n=arr.size(); //如果数组中没有小于k的数,那么第k个缺失的数字就是k for(int i=0;i<n;i++){原创 2022-03-31 22:58:34 · 340 阅读 · 0 评论 -
力扣-728题 自除数(C++)- 纯思路
题目链接:https://leetcode-cn.com/problems/self-dividing-numbers/题目如下:class Solution {public: vector<int> selfDividingNumbers(int left, int right) { vector<int> res; for(int i=left;i<=right;i++){ if(isValid(i))原创 2022-03-31 15:04:06 · 418 阅读 · 0 评论 -
力扣-1385题 两个数组间的距离值(C++)- 模拟
题目链接:https://leetcode-cn.com/problems/find-the-distance-value-between-two-arrays/题目如下:class Solution {public: int findTheDistanceValue(vector<int>& arr1, vector<int>& arr2, int d) { int res=0; for(auto e1:arr1)原创 2022-03-28 23:01:45 · 196 阅读 · 0 评论 -
力扣- 693题 交替位二进制数(C++)- 位运算
题目链接:https://leetcode-cn.com/problems/binary-number-with-alternating-bits/题目如下:class Solution {public: bool hasAlternatingBits(int n) { unsigned int n_n=n; int pre=0,cur=0; //取最后一位,并移除最后一位 pre=n_n&1;原创 2022-03-28 14:45:55 · 603 阅读 · 0 评论 -
力扣-509题 斐波那契数(C++)- dp
题目链接:https://leetcode-cn.com/problems/fibonacci-number/题目如下:class Solution {public: int fib(int n) { if(n==0) return 0; if(n==1) return 1; int array[33]; array[0]=0;array[1]=1; for(int i=2;i<=n;原创 2022-03-28 14:23:41 · 114 阅读 · 0 评论 -
力扣-617题 合并二叉树(C++)- 递归
题目链接:https://leetcode-cn.com/problems/merge-two-binary-trees/题目如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {}原创 2022-03-27 22:36:50 · 84 阅读 · 0 评论 -
力扣-剑指Offer 55-II题 平衡二叉树(C++)- dfs
题目链接:https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/题目如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL)原创 2022-03-27 20:36:04 · 892 阅读 · 0 评论 -
力扣-面试题01.01题 判定字符是否唯一(C++)- 排序
题目链接:https://leetcode-cn.com/problems/is-unique-lcci/题目如下:class Solution {public: bool isUnique(string astr) { quicksort(astr,0,astr.size()-1); for(int i=1;i<astr.size();i++){ if(astr[i]==astr[i-1]) return false;原创 2022-03-26 16:35:49 · 450 阅读 · 0 评论 -
力扣-278题 第一个错误的版本(C++)- 二分
题目链接:https://leetcode-cn.com/problems/first-bad-version/题目如下:// The API isBadVersion is defined for you.// bool isBadVersion(int version);class Solution {public: int firstBadVersion(int n) { int low=1,high=n; while(low<=high){原创 2022-03-26 14:12:32 · 386 阅读 · 0 评论 -
力扣-13题 罗马数字转整数(C++)- 哈希
题目链接:https://leetcode-cn.com/problems/roman-to-integer/题目如下:class Solution {public: int romanToInt(string s) { unordered_map<char,int> umap={ {'I',1}, {'V',5}, {'X',10}, {'L',50},原创 2022-03-26 13:24:18 · 450 阅读 · 0 评论 -
力扣-706题 设计哈希映射(C++)- 哈希
题目链接:https://leetcode-cn.com/problems/design-hashmap/题目如下:class MyHashMap {public: MyHashMap():data(N) { } void put(int key, int value) { int t=hash(key); for(auto it=data[t].begin();it!=data[t].end();it++){原创 2022-03-25 00:58:27 · 783 阅读 · 0 评论 -
力扣-705题 设计哈希集合(C++)- 哈希
题目链接:https://leetcode-cn.com/problems/design-hashset/题目如下:class MyHashSet {public: //有一个大小为N的数组vector,数组的每个位置是一个链表list(双链表) MyHashSet():data(N){}//构造函数初始化的一种方式 void add(int key) { int t=hash(key);//计算哈希值 for(auto it=da原创 2022-03-24 23:29:12 · 304 阅读 · 0 评论 -
力扣-1122题 数组的相对排序(C++)- 哈希
题目链接:https://leetcode-cn.com/problems/relative-sort-array/题目如下:class Solution {public: vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) { sort(arr1.begin(),arr1.end()); map<int,int>原创 2022-03-24 14:26:47 · 449 阅读 · 0 评论 -
力扣-面试题01.02题 判定是否互为字符重排(C++)- 哈希
题目链接:https://leetcode-cn.com/problems/check-permutation-lcci/题目如下:class Solution {public: bool CheckPermutation(string s1, string s2) { unordered_map<char,int> umap; for(auto e:s1){ umap[e]++; } fo原创 2022-03-23 22:17:04 · 439 阅读 · 0 评论 -
力扣-面试题 02.01题 移除重复节点(C++)- 哈希
题目链接:https://leetcode-cn.com/problems/remove-duplicate-node-lcci/题目如下:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public:原创 2022-03-23 01:51:30 · 605 阅读 · 0 评论 -
力扣-剑指Offer 15题 二进制中1的个数(C++)- 位运算
题目链接:https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/题目如下:class Solution {public: int hammingWeight(uint32_t n) { unsigned int _n=n; int result=0; while(_n){ if(_n&1) result++;//求最后一位原创 2022-03-22 01:15:18 · 267 阅读 · 0 评论 -
力扣-455题 分发饼干(C++)- 贪心
题目链接:https://leetcode-cn.com/problems/assign-cookies/题目如下:class Solution {public: int findContentChildren(vector<int>& g, vector<int>& s) { //贪心,先用最大的饼干满足胃口最大的小孩,依次向后遍历 sort(g.begin(),g.end());//胃口 sort(s原创 2022-03-18 23:02:27 · 894 阅读 · 0 评论 -
力扣-面试题10.05 稀疏数组搜索(C++)- 二分变形
题目链接:https://leetcode-cn.com/problems/sparse-array-search-lcci/题目如下:class Solution {public: int findString(vector<string>& words, string s) { int low=0,high=words.size()-1; while(low<=high){ int mid=low+(hig原创 2022-02-08 18:27:10 · 512 阅读 · 0 评论