自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(106)
  • 收藏
  • 关注

原创 AOP 面向切面编程--WPF Prism.Unity框架中集成的AOP

概念1、Aspect-Oriented Programming(面向切面编程),AOP就是对OOP(面向对象编程)的一种功能扩展。2、需要将核心业务与公共业务分离。AOP优势1、将通用功能从业务逻辑中抽离出来,可以省略大量重复代码,有利于代码的操作和维护。2、模块化开发,降低软件架构的复杂度。静态AOP采用装饰器模式或者代理模式实现。抽象类与实现类: public interface IInfoProcessor { void ReadInfo(string

2021-09-01 23:17:46 2601 1

原创 Prism.Unity 依赖注入(IOC)的使用

Prism+Prism.Unity的使用本文章使用的Prism、Prism.Unity版本:7.2.0.1422一、使用Prism.Unity构建一个Prism应用需要说明的是:老版本的Prism,构建WPF应用是新建一个类,继承自UnityBootstrapper。但是新版本的已经不建议这么做了,而是App类直接继承自PrismApplication,具体可以查看新版本中对UnitBootstrapper的注释说明:源码地址:https://github.com/PrismLibrary/Pris

2021-05-07 23:26:28 8058 9

原创 [C++]关于头文件中的防卫式声明(#ifndef...#pragma once)

大家知道,我们写.h文件时,通常会加上防卫式声明,有以下两种方式:1.宏定义#ifndef _FILENAME_#define _FILENAME_//...#endif2.编译器指令#pragma once但是,为什么头文件中需要添加这种防卫式声明呢?如果没有这样的声明,会出现怎样的问题。这里,先看一个例子。– “Car.h”,代码如下(并没有添加防卫式声明):// Car.hclass Car{// ...};– “Person.h”,代码如下(包含了Car.h文件)

2022-01-12 09:23:04 489

原创 编辑距离【leetcode 72】

解答动态规划class Solution {public: int minDistance(string word1, string word2) { // 获取字符串 word1 的长度 int m = word1.size(); // 获取字符串 word2 的长度 int n = word2.size(); if(m==0||n==0) return max(m,n); // .

2021-12-22 23:33:44 3422

原创 最 小路径和【leetcode 64】

解答动态规划#include <vector>#include <iostream>using namespace std;// @lc code=startclass Solution {public: int minPathSum(vector<vector<int>>& grid) { // m 表示有多少行 int m = grid.size(); .

2021-12-21 17:12:05 323

原创 打家劫舍 III【leetcode 337】

解答动态规划(树形DP)打劫一个树的最大收益,是 robIncludeRoot 和 robExcludeRoot 中的较大者。即每个子树都有两个状态下的最优解:没打劫 root、和有打劫 root 下的最优解。有两个变量共同决定一个状态:1、代表不同子树的 root 节点、2、是否打劫了 root。没打劫根节点,则左右子树的根节点可打劫可不打劫:dp[0] = 左子树的两个状态的较大值 + 右子树的两个状态的较大值。打劫了根节点,则左右子树的根节点不能打劫:dp[1] = root.val.

2021-12-21 15:26:08 482

原创 打家劫舍 II【leetcode 213】

解答动态规划#include <vector>using namespace std;class Solution {public: int rob(vector<int>& nums) { // 先获取全部房间的总数 int n = nums.size(); // 如果数组为空,表示没有房间,那么自然偷不到东西,直接返回 0 if(n==0) return 0; // 如.

2021-12-21 14:43:42 123

原创 打家劫舍【leetcode 198】

解答动态规划#include <vector>using namespace std;class Solution {public: int rob(vector<int>& nums) { // 先获取全部房间的总数 int n = nums.size(); // 设置一个数组 dp 用来存放前 n 个房间可以偷取的最大金额 // dp[0] 表示前 0 个房间可以偷取的最大金额 .

2021-12-21 14:21:32 127

原创 不同路径 II【leetcode 63】

解答动态规划#include <vector>using namespace std;// @lc code=startclass Solution {public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { // m 行 int m = obstacleGrid.size(); // n 列 .

2021-12-21 12:53:03 252

原创 不同路径【leetcode 62】

解答动态规划#include <vector>using namespace std;class Solution {public: int uniquePaths(int m, int n) { // 设置二维数组 dp 用来储存到达每个位置时不同路径的数量 // dp[0][0] 表示从第 0 行第 0 列到达第 0 行第 0 列时不同路径的数量 // dp[0][i] 表示从第 0 行第 0 列到达第 0 行第 i .

2021-12-21 11:19:05 124

原创 翻转二叉树【leetcode 226】

解答#include <algorithm>using namespace std;/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode.

2021-12-18 11:23:54 803

原创 买卖股票的最 佳时机含手续费【leetcode 714】

解答动态规划第122题的变形,只需要考虑买入股票时减去手续费即可#include <vector>#include <algorithm>using namespace std;class Solution {public: int maxProfit(vector<int>& prices, int fee) { int n = prices.size(); if(n<2) return 0; .

2021-12-18 11:07:52 241

原创 最 佳买卖股票时机含冷冻期【leetcode 309】

解答动态规划基于122题的变形第 i - 2 天【不持有】股票,第 i 天买入(考虑冷冻期)前天【不持有】股票,今天买入特殊处理:i<2时,不持有股票时的收益为0,所以代码为:i>=2?dp[i-2][0]:0dp[i][1] = max(dp[i-1][1],(i>=2?dp[i-2][0]:0)-prices[i]);#include <vector>#include <algorithm>using namespace std;clas.

2021-12-18 10:56:54 150

原创 买卖股票的最 佳时机 III【leetcode 123】

解答动态规划#include <vector>#include <algorithm>using namespace std;class Solution {public: int maxProfit(vector<int>& prices) { int n = prices.size(); //先获取数组的长度 if(n==0) return 0; //特殊处理 // 设置一个三维数组 d.

2021-12-18 10:34:11 135

原创 买卖股票的最 佳时机 II【leetcode 122】

解答动态规划#include <vector>#include <algorithm>using namespace std;class Solution {public: int maxProfit(vector<int>& prices) { int n = prices.size(); if(n<2) return 0; vector<vector<int>&g.

2021-12-18 10:30:45 262

原创 买卖股票的最 佳时机【leetcode 121】

解答一次遍历如果我是在历史最低点买的股票就好了!太好了,在题目中,我们只要用一个变量记录一个历史最低价格 minprice,我们就可以假设自己的股票是在那天买的。那么我们在第 i 天卖出股票能得到的利润就是 prices[i] - minprice。我们只需要遍历价格数组一遍,记录历史最低点,然后在每一天考虑这么一个问题:如果我是在历史最低点买进的,那么我今天卖出能赚多少钱?当考虑完所有天数之时,我们就得到了最好的答案。#include <vector>#include <ma.

2021-12-18 10:20:15 640

原创 买卖股票的最 佳时机 IV【leetcode 188】

解答#include <vector>#include <algorithm>using namespace std;// @lc code=startclass Solution {public: int maxProfit(int k, vector<int>& prices) { int n = prices.size(); //先获取数组的长度 if(n==0) return 0; //特殊处理 .

2021-12-17 23:11:17 747

原创 插入排序 C++

将数组中的数据分为两个区间,已排序区间和未排序区间。初始已排序区间只有一个元素,就是数组的第一个元素。插入算法的核心思想是取未排序区间中的元素,在已排序区间中找到合适的插入位置将其插入,并保证已排序区间数据一直有序。重复这个过程,直到未排序区间中元素为空,算法结束。插入排序也包含两种操作,一种是元素的比较,一种是元素的移动。当我们需要将一个数据 a 插入到已排序区间时,需要拿 a 与已排序区间的元素依次比较大小,找到合适的插入位置。找到插入点之后,我们还需要将插入点之后的元素顺序往后移动一位,这样才能腾出

2021-12-17 14:44:12 364

原创 选择排序 C++

选择排序每次会从未排序区间中找到最小的元素,将其放到已排序区间的末尾。#include <vector>#include <stdlib.h>using namespace std;class Solution {public: vector<int> sortArray(vector<int>& nums) { // 执行选择排序操作 selectSort(nums); r

2021-12-17 14:21:22 592

原创 冒泡排序 C++

冒泡排序只会操作相邻的两个数据。每次冒泡操作都会对相邻的两个元素进行比较,看是否满足大小关系要求。如果不满足就让它俩互换。一次冒泡会让至少一个元素移动到它应该在的位置,重复 n 次,就完成了 n 个数据的排序工作。#include <vector>#include <stdlib.h>using namespace std;class Solution {public: vector<int> sortArray(vector<int&

2021-12-17 14:08:20 537

原创 归并排序 C++

快速排序为先分隔在左右排序,归并排序为先左右排序再合并#include <vector>#include <stdlib.h>using namespace std;class Solution {public: //临时数组 vector<int> tempArr; vector<int> sortArray(vector<int>& nums) { //设置临时数组大小

2021-12-17 12:49:52 435

原创 快速排序 C++

快速排序实现的难点,就是如何将数组切分为左右两部分,可以用快慢指针和对撞指针实现。快慢指针#include <vector>#include <stdlib.h>using namespace std;class Solution {public: vector<int> sortArray(vector<int>& nums) { // 执行快速排序操作 quickSort(nums,0,nums

2021-12-17 11:00:04 583

原创 二叉树的最小深度【leetcode 111】

解答这道题的关键是搞清楚递归结束条件叶子节点的定义是左孩子和右孩子都为 null 时叫做叶子节点当 root 节点左右孩子都为空时,返回 1当 root 节点左右孩子有一个为空时,返回不为空的孩子节点的深度当 root 节点左右孩子都不为空时,返回左右孩子较小深度的节点值#include <algorithm>using namespace std;class Solution {public: int minDepth(TreeNode* root) { .

2021-12-16 09:57:55 497

原创 二叉树的最大深度 【leetcode 104】

解答#include <algorithm>class Solution {public: int maxDepth(TreeNode* root) { if(root==nullptr) return 0; //递归终止条件 int maxDepthLeft = maxDepth(root->left); //计算左子树最大深度 int maxDepthRight = maxDepth(root->right); .

2021-12-16 09:18:18 571

原创 零钱兑换【leetcode 322】

解答因为硬币可以重复使用,因此这是一个完全背包问题。dp[i] 表示想要凑齐 i 元需要的最少硬币个数dp[0] 表示想要凑齐 0 元需要的最少硬币个数dp[1] 表示想要凑齐 1 元需要的最少硬币个数dp[14] 表示想要凑齐 14 元需要的最少硬币个数#include <vector>using namespace std;// @lc code=startclass Solution {public: int coinChange(vector<int.

2021-12-15 17:57:50 327

原创 通过删除字母匹配到字典里最长单词【leetcode 524】

解答双指针1#include <string>#include <vector>#include <algorithm>using namespace std;class Solution {public: string findLongestWord(string s, vector<string>& dictionary) { string longestWord = ""; for (in.

2021-12-14 17:20:49 364

原创 合并两个有序数组【leetcode 88】

解答方法1:临时数组+双指针#include <vector>using namespace std;class Solution {public: void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) { vector<int> tempArr(m+n); //nums1指针 int i = 0;.

2021-12-14 16:14:01 769

原创 验证回文字符串2【leetcode 680】

解答回文字符串特点关于中间字符或中间位置对称,就是左右对应字符是相等。我们需要前后两个指针,每次我们只要保证指针指向字符是相等的,那这个字符串就是回文字符串,返回true;当两个指针字符不相等时最多可以删除一个字符后继续比较,删除的字符可能是前面指针所指字符或者后面指针所指字符#include <string>using namespace std;class Solution {public: bool validPalindrome(string s) { .

2021-12-11 13:40:19 428

原创 反转字符串中的元音字母【leetcode 345】

解答使用双指针,一个指针从头向尾遍历,一个指针从尾到头遍历,当两个指针都遍历到元音字符时,交换这两个元音字符。为了快速判断一个字符是不是元音字符,我们将全部元音字符添加到集合 HashSet 中,从而以 O(1) 的时间复杂度进行该操作。#include <string>#include <unordered_set>using namespace std;class Solution {public: string reverseVowels(strin.

2021-12-11 11:58:41 338

原创 四数之和【leetcode 18】

解答排序 + 双指针解题思想:在三数之和的基础上多一层循环即可。#include <vector>#include <algorithm>using namespace std;class Solution {public: vector<vector<int>> fourSum(vector<int>& nums, int target) { vector<vector<int&gt.

2021-12-11 11:31:19 319

原创 最接近的三数之和【leetcode 16】

解答简单一句话,先排序,然后固定第一个数a,再然后b、c只能从两边向中间靠(在a之后)。细节条件就是去重处理(i,start,end三个索引的去重都要考虑)#include <vector>#include <algorithm>#include <math.h>using namespace std;// @lc code=startclass Solution {public: int threeSumClosest(vector<.

2021-12-11 00:00:25 263

原创 三数之和【leetcode 15】

简单一句话,先排序,然后固定第一个数a,再然后b、c只能从两边向中间靠(在a之后)。细节条件就是去重处理解答1、官方代码:#include <vector>#include <algorithm>using namespace std;class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { if (num.

2021-12-10 23:19:24 93

原创 平方数之和【leetcode 633】

解答双指针可以看成是在元素为 0~target 的有序数组中查找两个数,使得这两个数的平方和为 target,如果能找到,则返回 true,表示 target 是两个整数的平方和。本题和 167. Two Sum II - Input array is sorted 类似,只有一个明显区别:一个是和为 target,一个是平方和为 target。本题同样可以使用双指针得到两个数,使其平方和为 target。本题的关键是右指针的初始化,实现剪枝,从而降低时间复杂度。设右指针为 x,左指针固定为 0,.

2021-12-10 20:21:19 122

原创 两数之和 II - 输入有序数组【leetcode 167】

解答使用双指针,一个指针指向值较小的元素,一个指针指向值较大的元素。指向较小元素的指针从头向尾遍历,指向较大元素的指针从尾向头遍历。如果两个指针指向元素的和 sum == target,那么得到要求的结果;如果 sum > target,移动较大的元素,使 sum 变小一些;如果 sum < target,移动较小的元素,使 sum 变大一些。数组中的元素最多遍历一次,时间复杂度为 O(N)。只使用了两个额外变量,空间复杂度为 O(1)。#include <vector.

2021-12-10 19:49:09 447

原创 长度最小的子数组【leetcode 209】

#include <vector>#include <algorithm>using namespace std;class Solution {public: int minSubArrayLen(int target, vector<int>& nums) { int result = INT_MAX; bool flag = false; int sum = 0; int l.

2021-12-09 18:36:43 228

原创 无重复字符的最长子串【leetcode 3】

解题思路:滑动窗口+哈希表#include <string>#include <unordered_set>#include <algorithm>using namespace std;class Solution {public: int lengthOfLongestSubstring(string s) { unordered_set<char> set; int right = 0; .

2021-12-09 10:59:28 186

原创 链表反转【leetcode 206】

递归写法: ListNode* reverseList(ListNode* head) { if (head==nullptr||head->next==nullptr) { return head; } ListNode* node = reverseList(head->next); head->next->next = head; head->n

2021-12-08 15:07:53 88

原创 QuartZ 定时任务(二)

可视化界面管理在任务执行的时候,我们需要实时监控,或者在一些场景下,我们需要做些人工介入;—最好能有一个可视化的界面;在QuartZ中是可以支持1.新建一个Web程序(AspNetMVC, webfrom,控制台)2.Nuge引入QuartZ+CrystalQuartz.Remote3.在StdSchedulerFactory配置相关信息(Scheduler的运行的时候需要使用到相关的类库+端口号)4.统一端口号,监控端去访问统一的端口号下的CrystalQuartzPanel.axd就可以通过

2021-11-06 16:34:36 520

原创 QuartZ 定时任务

应用场景1.需要在每天/每月/年的某个时间点执行一部分代码2.需要我们的项目每隔多长时间来执行一部分代码3.需要我们的项目某一个业务场景下,满足某一个条件后去执行一段代码QuartZ介绍Quartz.NET是一个强大、开源、轻量级的任务调度框架。任务调度在我们的开发中经常遇到,如说:每天晚上三点让程序或网站执行某些代码,或者每隔5秒种执行一个方法等。Windows计划任务也能实现类似的任务调度,但是Quartz.net有一些有优秀的特性,如:数据库支持,集群,插件,支持cron-like表达式

2021-11-05 00:00:41 400

原创 .net core 5 切面编程AOP

AOP的三种应用ASP.NET Core框架中的AOP—中间件 (管道处理模型)ASP.NET Core框架中的AOP—Filter (Controller层)IOC支持AOP扩展—应用于Service层(业务逻辑层)中间件:Filter:业务逻辑层:Filter1.Authorize 顺序排第一2.ResourceFilter 顺序排第二—主要是缓存3.Action 排在Resouce之后4.Result5.Exception 处理异常的...

2021-10-27 23:00:30 528

空空如也

空空如也

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

TA关注的人

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