自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

小明的博客

傲不可长 欲不可纵 乐不可极 志不可满

  • 博客(274)
  • 资源 (5)
  • 收藏
  • 关注

原创 Leecode<每日一题>正则表达式匹配

Leecode<每日一题>正则表达式匹配题目链接思路:递归+枚举class Solution {public:bool isMatch(string s, string p) { int num = 0; for (int i = 0; i < p.length(); i++) { if (p[i] == '*') continue; if (i + 1 < p.length() && p[i + 1] == '*') { if (p[i] =

2021-08-19 11:22:27 194

原创 Leecode<每日一题>N 皇后

Leecode<每日一题>N 皇后题目链接思路:回溯法+限制数组class Solution {public: bool lie[10]{}; bool up[20]{}; bool down[20]{}; int choose[10]{}; vector<vector<string>> rt; void dfs(int cur,int n) {

2021-08-18 10:11:31 213

原创 Leecode<每日一题>学生出勤记录 II

Leecode<每日一题>学生出勤记录 II题目链接思路:动态规划,dp[i][0],表示n == i,缺勤次数为0时的可能情况数。dp[i][1],表示n == i,缺勤次数为1时的可能情况数。class Solution {public: int checkRecord(int n) { long long dp[100010][2]{}; dp[1][0] = 2,dp[1][1] = 1; dp[2][0] = 4,dp[2][1]

2021-08-17 10:59:40 184

原创 Leecode<每日一题>优美的排列

Leecode<每日一题>优美的排列题目链接思路:枚举优化法,将每个位置可选择的情况枚举出来,然后通过递归枚举每一种可行的情况。class Solution {public: vector<vector<int>> ab_use = { {}, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, {1,2,4,6,8,10,12,14}, {1,3,6,9,12,15}, {1,2,4,8,12}, {1,5,10,15}, {

2021-08-16 14:27:45 121

原创 Leecode<每日一题>出界的路径数

Leecode<每日一题>出界的路径数题目链接思路:动态规划,dp[i][j][step] 表示在位置[i,j]处,可移动距离为step时,出界的路径数。class Solution {public:int dp[51][51][51]{};vector<vector<int>> dir= { {1,0},{-1,0},{0,1},{0,-1} }; int findPaths(int m, int n, int maxMove, int startRow, i

2021-08-15 15:49:46 130

原创 Leecode<每日一题>统计不开心的朋友

Leecode<每日一题>统计不开心的朋友题目链接思路:先打两张表,一张是匹配表,另一张是两个人之间的好感优先级表,然后枚举就行。class Solution {public: int unhappyFriends(int n, vector<vector<int>>& preferences, vector<vector<int>>& pairs) { int match[510][510];

2021-08-14 10:21:12 117

原创 Leecode<每日一题>数字 1 的个数

Leecode<每日一题>数字 1 的个数题目链接思路:找规律,统计每一位上1的个数class Solution {public: int countDigitOne(int n) { string num = to_string(n); int sum = 0; int fro = 0; for (int i = 0; i < num.length(); i++) { int yu = (int)pow(10, num.size()-i-1); in

2021-08-13 11:22:33 155

原创 Leecode<每日一题>最长回文子序列

Leecode<每日一题>最长回文子序列题目链接思路:动态规划dp[i][j]表示下标i到j的区间内,最大的回文子序列的长度。动态转移方程:dp[i][end] = dp[i + 1][end - 1] + 2; //区间首位相同的转移方程dp[i][end] = max(dp[i][end - 1],dp[i+1][end]); //区间首位不同的转移方程class Solution {public: int longestPalindromeSubseq(string s

2021-08-12 10:38:56 141

原创 Leecode<每日一题>等差数列划分 II - 子序列

Leecode<每日一题>等差数列划分 II - 子序列题目链接思路:动态规划+哈希表class Solution {public:typedef long long ll; int numberOfArithmeticSlices(vector<int>& nums) { auto tab = vector<unordered_map<int, int>>(nums.size() + 1); int sum = 0; for (int

2021-08-11 10:37:05 101

原创 Leecode<每日一题>环形数组是否存在循环

Leecode<每日一题>环形数组是否存在循环题目链接思路:彩色标记法,同一入口走过的路用同一种颜色标记时间复杂度o(n)空间复杂度o(1)class Solution {public:#define k 1010bool circularArrayLoop(vector<int>& nums) { for (int i = 0; i < nums.size(); i++){ if (nums[i] != 0) { int sign = nums[i]

2021-08-07 11:03:01 82

原创 Leecode<每日一题>找到最终的安全状态

Leecode<每日一题>找到最终的安全状态题目链接思路:拓扑排序,先根据原图记录一下反图,然后将原图中出度为0的点加入队列中,然后将以此结点为边的目标点的源结点出度减一,然后再将出度为0的点加入队列中,直至队列为空。vector<int> eventualSafeNodes(vector<vector<int>>& graph) { vector<int> outdu(graph.size()); vector<int> rs

2021-08-05 15:02:45 86

原创 Leecode<每日一题> 网络延迟时间

Leecode<每日一题> 网络延迟时间题目链接思路:其实就是求最小生成树,我使用的是prim算法维护两个集合,一个是已添加结点集合,一个是未添加集合,循环n-1次,维护一个距离数组,每次循环添加一个离源点最短的结点进入集合,并以此更新结点的距离。int networkDelayTime(vector<vector<int>>& times, int n, int k) { auto graph = vector<vector<pair<int,i

2021-08-02 11:22:53 155

原创 Leecode<每日一题>二叉树的垂序遍历

Leecode<每日一题>二叉树的垂序遍历题目链接思路:map+multiset+dfs这题其实就是按照纵坐标、横坐标、值依次排序。map 键:坐标 值:multiset(用于给同一坐标的值排序),然后重写map比较器,先纵坐标再横坐标我的代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right;

2021-07-31 10:53:54 148

原创 Leecode<每日一题>二叉树中所有距离为 K 的结点

Leecode<每日一题>二叉树中所有距离为 K 的结点题目链接思路:先遍历一遍将每个节点的父节点存储下来,然后从target开始层次遍历,找到距离为k的节点即可。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL),

2021-07-28 10:35:15 131

原创 Leecode<每日一题>得到子序列的最少操作次数

Leecode<每日一题>得到子序列的最少操作次数题目链接思路:实际上这题是求公共最长子序列,我是用哈希表+动态规划+二分查找哈希表存target元素所对应的下标dp[i] 表示长度为i的子序列元素的最后位置二分查找每次找到第一个比mp[x]大的元素,并更新他;class Solution {public: int dp[100100]{};int minOperations(vector<int>& target, vector<int>&

2021-07-26 11:15:39 122

原创 Leecode——8. 字符串转换整数 (atoi)

Leecode——8. 字符串转换整数 (atoi)题目链接思路:模拟,注意用long long 存class Solution {public: int myAtoi(string s) { int i=0; while(s[i] == ' ') { i++; } int z = 1; if(s[i] == '-') { z =

2021-07-24 10:29:04 97

原创 Leecode<每日一题>替换隐藏数字得到的最晚时间

Leecode<每日一题>替换隐藏数字得到的最晚时间题目链接思路:枚举所有情况class Solution {public: string maximumTime(string time) { if(time[0] == '?' && time[1] == '?') { time[0] = '2'; time[1] = '3'; } if(time[0] == '

2021-07-24 10:03:55 103

原创 Leecode——139. 单词拆分

Leecode——139. 单词拆分题目链接思路:动态规划+哈希表 dp[i]表示从0下标开始到i的字符串是否可以被拆分class Solution {public: bool wordBreak(string s, vector<string>& wordDict) { unordered_map<string, bool> mp; for (auto& x : wordDict) mp[x] = true; a

2021-07-23 20:42:12 107

原创 Leecode——7. 整数反转

Leecode——7. 整数反转题目链接注意:先比较,再累乘,否者会越界class Solution {public: int reverse(int x) { int rev = 0; while (x) { if (rev < INT_MIN / 10 || rev > INT_MAX / 10) { return 0; } int digi

2021-07-23 18:49:40 87

原创 Leecode<每日一题>寻找重复数

Leecode<每日一题>寻找重复数题目链接思路:快慢指针class Solution {public: int findDuplicate(vector<int>& nums) { int slow=0,fast=0; do { slow = nums[slow]; fast = nums[nums[fast]]; }while(nums[slow] != n

2021-07-23 17:11:47 138

原创 Leecode<每日一题>检查是否区域内所有整数都被覆盖

Leecode<每日一题>检查是否区域内所有整数都被覆盖题目链接思路:差分数组class Solution {public: int f[52]{}; bool isCovered(vector<vector<int>>& ranges, int left, int right) { for (auto& x:ranges) { f[x[0]]++; f[x[1] + 1]--; } int sum = 0; for (int i

2021-07-23 10:21:34 95

原创 Leecode——6. Z 字形变换

Leecode——6. Z 字形变换题目链接思路:遍历字符串,沿着z字模拟,可以确定当前字符将会在第几行,然后直接将该字符添加到相应行的字符串中,最后将每一行的字符串拼接起来,便是答案。class Solution {public: string convert(string s, int numRows) { if(numRows == 1) return s; vector<string> temp( min( numRows, (

2021-07-22 15:23:34 82

原创 Leecode——5.最长回文子串

Leecode——5.最长回文子串题目链接思路:动态规划,dp[i][j] 表示i到j区间的字符串是否为回文子串动态转移方程:dp[i][j] = ((dp[i+1][j-1] || i==1) && s[i] == s[j])class Solution {public: bool dp[1010][1010] = {}; string longestPalindrome(string s) { string rt{}; i

2021-07-22 14:39:45 73

原创 Leecode<每日一题>复制带随机指针的链表

Leecode<每日一题>复制带随机指针的链表题目链接思路:先将老结点与新结点一一对应,在处理next和random指针。class Solution {public:Node* copyRandomList(Node* head) { unordered_map<Node*, Node*> mp; Node* p = head; while (p) { Node* nnew = new Node(p->val);

2021-07-22 10:14:18 54

原创 Leecode<每日一题>两个链表的第一个公共节点

Leecode<每日一题>两个链表的第一个公共节点题目链接思路:先记录两个链表的长度,然后将链表长度长的那个向后移至和短的链表一样长,再遍历链表比对就行了。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {

2021-07-21 09:43:48 69

原创 Leecode<每日一题>数组中最大数对和的最小值

Leecode<每日一题>数组中最大数对和的最小值题目链接思路:排序后,用首位加末尾,第二位加倒数第二位,依次相加,维护 最大值。class Solution {public: int minPairSum(vector<int>& nums) { sort(nums.begin(),nums.end()); int mmax = 0; for(int i=0;i<nums.size()/2;i++)

2021-07-20 09:32:50 56

原创 Leecode<每日一题>变位词组

Leecode<每日一题>变位词组题目链接思路:排序然后用哈希表判重,再把相同的丢进同一个vector中class Solution {public: vector<vector<string>> groupAnagrams(vector<string>& strs) { unordered_map<string, vector<string>> mp; for (auto& x : strs) {

2021-07-19 17:21:19 70

原创 Leecode<每日一题>最高频元素的频数

Leecode<每日一题>最高频元素的频数题目链接思路:排序+滑动窗口int maxFrequency(vector<int>& nums, int k) { if (nums.size() == 0) return 0; sort(nums.begin(), nums.end()); int res = 1; for (int i = 0, j = 0; i < nums.size() && j < nums.size();) { if

2021-07-19 11:08:45 82

原创 Leecode<剑指offer>三数之和

Leecode<剑指offer>三数之和题目链接思路:计数数组+枚举+set去重,枚举a与b,在计数数组中判断-(a+b)是否存在,将结果都放在set集合中去重。class Solution {public:static const int mmax = 100001;int ct[2*mmax] = {0};bool check[mmax] = { false };vector<vector<int>> threeSum(vector<int>&

2021-07-17 17:00:49 78

原创 Leecode<剑指offer>二叉树的深度

Leecode<剑指offer>二叉树的深度题目链接思路:深搜class Solution {public:int depth(TreeNode* node){ if (node == nullptr) return 0; int l = depth(node->left); int r = depth(node->right); return l > r ? l + 1 : r + 1;}int maxDepth(TreeNode* r

2021-07-17 11:17:50 128

原创 Leecode<每日一题>连续子数组的最大和

Leecode<每日一题>连续子数组的最大和题目链接思路:记录前缀和最小的情况,每次用当前前缀和减去最小前缀和,并记录最大值,即为最终答案。int maxSubArray(vector<int>& nums) { int sum = 0; int mmin = 0; int res = -1e9; for (auto& x : nums) { sum += x; res = max(res, sum -

2021-07-17 10:36:37 109

原创 Leecode<每日一题>H 指数

Leecode<每日一题>H 指数题目链接思路:计数数组,然后从低到高枚举每一种情况class Solution {public:int hIndex(vector<int>& citations) { vector<int> count_num(citations.size() + 1); for (int i = 0; i < citations.size(); i++) { if (citations[i] &g

2021-07-16 11:19:25 64

原创 Leecode<每日一题>在排序数组中查找数字 I

Leecode<每日一题>在排序数组中查找数字 I题目链接思路:二分查找,分别查找最左边和最右边的targetint search(vector<int>& nums, int target) { if (nums.size() == 0) return 0; int l = 0, r = nums.size() - 1; while (l <= r) { int mid = (l + r) / 2; if (

2021-07-16 10:21:01 69

原创 Leecode<每日一题>减小和重新排列数组后的最大元素

Leecode<每日一题>减小和重新排列数组后的最大元素题目链接思路:先排序,然后统计符合条件的数的个数,即为最大值class Solution {public: int maximumElementAfterDecrementingAndRearranging(vector<int>& arr) { sort(arr.begin(), arr.end()); int num = 0; for (int i = 0;i<arr.size();i

2021-07-15 20:11:20 84

原创 Leecode<每日一题>下一个排列

Leecode<每日一题>下一个排列题目链接思路:从右向左找到第一个非递减的数,然后将其与它右边所有数中比它大一号的数交换,然后将它右边所有剩下的数逆置即可。class Solution {public: void nextPermutation(vector<int>& nums) { int len = nums.size(); if (len == 1) return; bool flag = false; for (int i =

2021-07-15 15:45:05 120

原创 Leecode<每日一题>基于时间的键值存储

Leecode<每日一题>基于时间的键值存储题目链接思路:哈希表+二分查找struct node{ string value; int time; node(string v,int t):value(v),time(t) {}};class TimeMap {public: unordered_map<string, vector<node>> mp; /** Initialize your data struc

2021-07-10 14:52:23 74

原创 Leecode<每日一题>火柴拼正方形

Leecode<每日一题>火柴拼正方形题目链接思路:预处理的时候判断一下火柴的长度总和是否是4的倍速,然后深度优先搜索,一条边一条边的凑到sum/4,凑到三条边的时候就行了。注意:将火柴的长度从大到小排序,这样false的数据会更快执行完。class Solution {public:bool dfs(vector<int>& matchsticks,int he,int edge,int target){ if (he == target) { edge++;

2021-07-09 18:31:41 161

原创 Leecode<每日一题>主要元素

Leecode<每日一题>主要元素题目链接思路:玩一个诸侯争霸的游戏,假设你方人口超过总人口一半以上,并且能保证每个人口出去干仗都能一对一同归于尽。最后还有人活下来的国家就是胜利。那就大混战呗,最差所有人都联合起来对付你(对应你每次选择作为计数器的数都是众数),或者其他国家也会相互攻击(会选择其他数作为计数器的数),但是只要你们不要内斗,最后肯定你赢。最后能剩下的必定是自己人。//转自知乎class Solution {public: int majorityElement(vector&

2021-07-09 11:32:33 66

原创 Leecode<每日一题>统计好数字的数目

Leecode<每日一题>统计好数字的数目题目链接思路:其实就是求20的n/2次方,快速幂。#define m (int)(1e9+7)class Solution {public:long long binpow(long long a, long long b) { a %= m; long long res = 1 % m; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >

2021-07-08 17:39:58 76

原创 Leecode<每日一题>和相同的二元子数组

Leecode<每日一题>和相同的二元子数组题目链接解题思路:计数数组加前缀和,枚举子数组的结束坐标,并一边记录前缀和与前缀和的计数情况,那么以当前元素结束的连续子数组的个数就为前缀和减去目标数的计数情况,依此遍历一遍即可,官方题解使用哈希表来计数,但在能用数组的情况下,还是优先使用数组,时间效率更高。class Solution {public:static const int mmax = 30010;int mp[mmax] = { 0 };int numSubarraysWithSum

2021-07-08 14:35:07 95

Android开发的贪吃蛇(专门用于课程设计)

非常好用的课程设计,能直接运行,好东西,注释全,改改就能交,好东西 当然贵,自己在工作中研发的小项目

2018-01-03

Android开发的数独(特别好用的课程设计)

特别好用的课程设计,改改就能交,代码能直接运行,好东西,注释全,好东西 当然贵,自己在工作中研发的小项目

2018-01-03

android开发的记账本(特别好用的课程设计)

特别好用的课程设计,代码能直接运行,好东西,注释全,改改就能交,好东西 当然贵,自己在工作中研发的小项目

2018-01-03

五子棋应用程序的简单实现

Android-五子连珠 实现功能: 1,五子棋的逻辑实现 2,悔棋 3,重新开局 4,背景音乐的开始和暂停 系列博客:http://blog.csdn.net/sb_ihateyou/article/details/76202896

2017-07-27

贪吃蛇应用程序的简单实现

Android-贪吃蛇 实现功能: 1、贪吃蛇的逻辑实现 2、重新开局 2、播放背景音乐

2017-07-27

空空如也

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

TA关注的人

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