自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 217 - leetcode -存在重复元素 -数据结构类 先排序再操作

第一种解法 先快排再挨个比较是否重复第二种解法 直接利用数据结构#include <vector>using namespace std;class Solution {public: bool containsDuplicate(vector<int>& nums) { if(nums.empty()) return false; sort(nums.begin(),nums.end());

2021-05-09 16:59:40 96

原创 42 - 算法 - 198-打家劫舍-动态规划

// 动态规划 // 当前状态 前两个状态 dp[i] = max(dp[i-2]+num[i] , dp[i-1]) ; using namespace std;class Solution {public: int rob(vector<int>& nums) { if(nums.empty()) return 0; if(nums.size() == 1) return nums[0];

2021-04-20 23:07:40 107

原创 46 - 算法 -Leetcode 168 -位运算 类型模拟倒序利用vector

// 位运算 1<<i 位 来实现位运算 class Solution {public: uint32_t reverseBits(uint32_t n) { uint64_t res = 0; vector<int> vec; for(int i=0;i<32;i++) { if( ((1<<i)&n) != 0) {

2021-04-17 22:53:33 118

原创 46 - 算法 -Leetcode-189-旋转数组-数据结构vector或者reverse函数

// 借助vector来完成// 直接reverse函数实现//1class Solution {public: void reverse(vector<int> &nums,int l,int r) { if(l >= r) return; while(l <= r) { int temp = nums[l]; nums[l] = nums[r];

2021-04-17 16:41:11 86

原创 46 -算法 - Leetcode -169 - 多数元素 - map insert 迭代器

// map 的用法 m.insert返回值 std::pair<std::vector<int>::iterator, // // bool> res ,插入成功 res.second 为true 否则为false // std::vector<int>::iterator n =map.begin();#include <vector>#include <map>using namespace std;class So

2021-04-17 15:55:22 76

原创 46 - 算法 - Leetcode 168 -26进制 --减一

//奇怪 的地方就是没有从 0 开始 n-1 进制要从0开始 所以减l//% 是从 0 - 25 #include <string>using namespace std;class Solution {public: string convertToTitle(int n) { string s=""; while(n!=0){ int temp = (n-1)%26; s = (char)('A'

2021-04-17 12:32:41 97

原创 47 - 算法 - Leetcode -167-两数之和 - 输入有序数组

// o(n) 的复杂度 #include<vector>using namespace std;class Solution {public: vector<int> twoSum(vector<int>& numbers, int target) { int len = numbers.size(); vector<int> index; int j = len-1;

2021-04-16 22:10:22 61

原创 47 - 算法 - Leetcode-160 -相交链表

// 链表对齐 - 160 相交链表class Solution {public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { int lenA = 0; int lenB = 0; ListNode * temA = headA; ListNode * temB = headB; while(temA != NULL)

2021-04-16 21:33:08 75

原创 46 - 算法 - Leetcode-155-最小栈

//更新当前的状态 不要漏掉了class MinStack {public: /** initialize your data structure here. */ stack<int> temStack; int min=INT_MAX; //当前最小值 MinStack() { } void push(int val) { if(val <= min) min = val; temS

2021-04-16 18:45:00 78

原创 46 - 算法 -Leetcode-141-环形链表-快慢指针

* 快慢指针法:设定两个指针,如果快指针被慢指针追上,那么一定有环 */class Solution {public: bool hasCycle(ListNode *head) { ListNode *l1,*l2; l1=l2=head; while(l1!=NULL && l2!=NULL &&l1->next !=NULL){ l1 = l1->next->nex.

2021-04-16 00:13:12 46

原创 47 - 算法 - 记住常用位运算-Leetcode-136-只出现一次的数字

// 位运算 相同的 a^a = 0 a^0 = a 其它 a&a = a a&0 = 0class Solution {public: int singleNumber(vector<int>& nums) { int res = 0; for(int i=0;i<nums.size();i++) { res ^=nums[i]; } return

2021-04-15 23:24:44 68

原创 47 -算法 -回文串 -Leetcode 125 - 验证回文串

// 模块化 自己在单独写一个函数都忘了 string 也有size a ASCII码为97 小a//为65 【NUM1 - 'A'】%32 == [NUM2 - 'A']%32 忽略大小写#include <string>using namespace std;class Solution {public: bool isAlphaNum(char &ch){ if(ch>='a' && ch<='z')

2021-04-15 21:05:02 49

原创 48 - LeetCode 122 121. 买卖股票的最佳时机

// algorigthm 的 min 和 max 函数用于保存当前状态#include <algorithm>#include <vector>using namespace std;class Solution {public: int maxProfit(vector<int>& prices) { if(prices.empty()) return 0; int profit =

2021-04-14 23:11:18 57

原创 48 - 算法 - leetcode 118 杨辉三角

//感觉两种思路 一种直接全都有 数组 可变数组 vector<vector<int> (n)//数组与可变数组初始化 #include <vector>using namespace std;class Solution {public: vector<vector<int>> generate(int numRows) { vector<vector<int>> result(numRows)

2021-04-14 21:59:39 62

原创 49 - 算法 - Leetcode 112 路径总和 -二叉树递归 带参数一起递归

// 感觉都是那几个固定的格式 寻找临时 单前树 状态输入减小 int sum递减//树递归 所带的参数也递归减少class Solution {public: bool hasPathSum(TreeNode* root, int sum) { if(root == NULL) return false; if(root->left == NULL && root->right == NU

2021-04-14 00:19:13 49

原创 49 - 算法 - Leetcode-111 -二叉树的最小深度 -递归循环

//树除了 递归 还有 循环 左右比较class Solution {public: int minDepth(TreeNode* root) { queue<TreeNode*> temq1; queue<TreeNode*> temq2; if(root == nullptr) return 0; int count =1; temq1.push(root); TreeNo

2021-04-13 23:13:21 55

原创 49 - 算法 - LeetCode 110 平衡二叉树 - 求二叉树的高度 -双重递归

// 求二叉树的高度函数 nullptr为0 然后累加 +1 return left-right// 结论都还是递归 当前状态 多加了一个递归求高度 双重递归class Solution {public: //求二叉树的高度 int height(TreeNode * root) { if(root == nullptr) return 0; TreeNode * left = root->left; TreeNode *

2021-04-13 22:21:27 90

原创 49 - 算法 - 二叉树 - leetcode108.-将有序数组转换为二叉搜索树-中序遍历 - vector

//vec 构造函数 vec.begin() end() + num ={134} =other vector//一直到null 就行 new(int) root->left ->right// 树 递归 层序遍历 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * Tree.

2021-04-13 20:29:38 60

原创 49 -算法 -LeetCode 107 107. 二叉树的层序遍历 II 栈队列vector

// 最好别 直接 !left 或者 !right 来判断是否为空 判断的是地址 很尴尬// 直接 left != null rigth != null //queue front pop push empty size 是否为空 是true//stack top pop push empty size pop pop不返回元素//vector clear size [] vec.erase(vec.begin()+i,vec.end()+j);删除区间[i,j-1];区间从0开始 push_bac

2021-04-13 00:27:46 97

原创 50 - 算法- LeetCode 104 -二叉树

//代码还是要精简?? 发现max函数比三元运算符效率高class Solution {public: int maxDepth(TreeNode* root) { if(!root) return 0; else return max(maxDepth(root->left),maxDepth(root->right))+1; }};

2021-04-12 23:19:33 54

原创 50 - 算法 -二叉树 - 递归 - LeetCode 101

// 学会辅助函数 递归 main初始化状态class Solution {public: bool isEquation(TreeNode *left,TreeNode* right) { if(left == nullptr && right == nullptr) return true; if(left == nullptr || right == nullptr) return false; if(left-&gt

2021-04-12 23:00:28 55

原创 51 -算法 -斐波拉奇数列 -LeetCode 70 -递推

// 斐波拉奇数列 // 递归 和 递推 static int count = 0;class Solution {public: int climbStairs(int n) { if(n == 1 || n == 0) return 1; if(n == 2) return 2; int s1 = 1; //f(n-1) -f(1) int s2 = 2; //f(n-2) -f(2) int tem

2021-04-11 18:43:28 87

原创 51 -算法 -LeetCode 53最大子序和 动态规划

//版本1 动态规划保存当前状态 版本class Solution {public: int maxSubArray(vector<int>& nums) { int dp[30001]={0}; dp[0] = nums[0]; int max=dp[0]; for(int i=1;i<nums.size();i++) { dp[i] = (dp[i-1]+nu

2021-04-11 12:55:51 70

原创 51 -leetcode 38 -字符串

// LeetCode 38 字符串 to_string int to string char 直接变为string//边界情况 for int i=0 i<.size() 比较的活 i+1 与i 比 i<size -1; 从第二个开始class Solution {public: string countAndSay(int n) { string res ="1"; string tem = ""; int count =0;

2021-04-11 11:06:08 64

原创 52 - 算法 - LeetCode 28 - 实现 strStr() -kmp

//又写了一下 kmp 参考以前的把它搞出来了 一个模式串next数组 一个遍历串 模式跳转 next[0]已经知道 从1开始 不等于 》0 && == 加加 class Solution {public: void make_next(string parttern,int *next) { int q =0; next[0] = 0; for(int i=1 ; i<parttern.l.

2021-04-10 22:03:35 79

原创 52 - 算法 - 数据结构 vector

//27 移除元素 数据结构 vec erase方法 左闭右开 vc+len,vc+size() 全删。class Solution {public: int removeElement(vector<int>& nums, int val) { int len = 0; for(int i=0;i<nums.size();i++) { if(nums[i] != val)

2021-04-10 18:23:19 66

原创 52 -算法 -数据结构类 Leetcode26 删除有序数组中的重复项

// 两个元素 比较 数组 index 链表指针 数组类class Solution {public: int removeDuplicates(vector<int>& nums) { if(nums.size() == 0) return 0; int len=1;// 当前数组中已经筛选出来的非重复元素的个数 for(int i=1;i<nums.size();i++){

2021-04-10 17:33:14 58

原创 52 - 算法 - LeetCode 21 数据结构链表 头插法 递归

//递归解法 可以不借助于另一个指针 递归 返回现有的变量节点 注意返回类型 class Solution {public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if(l1 == NULL){ return l2; }else if(l2 == NULL){ return l1; }else{ if(l1

2021-04-10 15:37:09 62

原创 52 - 算法 - LeetCode 20 数据结构类 stack

// 数据结构类,考验栈的用法 操作顺序之类的 学会用empty() true表示就是空#include <string>#include <stack>using namespace std;class Solution {public: bool isValid(string s) { stack<char> tempStack; for(char& c: s){ switch(c){

2021-04-10 14:56:11 59

原创 52 - 算法- leetcode 14 最长公共前缀

// leetcode 14 最长公共前缀 str.sub(index1,index2)这个函数不清楚// for(vector中的类class : vector) for 循环中的index 和 i不一样 //多想一想 思路清晰的 往下面做#include <string>#include <vector>using namespace std;class Solution {public: string longestCommonPrefix(vect

2021-04-10 02:14:49 50

原创 52 - LeetCode-13 -罗马数字转整数_罗马数字转数字

//LeetCode-13-数组和mapclass Solution {public: int romanToInt(string s) { map<char,int> map; map['M'] = 1000; map['D'] = 500; map['C'] = 100; map['L'] = 50; map['X'] = 10; map['V'] = 5; .

2021-04-10 01:30:37 59

原创 53 - 9. 回文数

class Solution {public: bool isPalindrome(int x) { if(x == 0) return true; if(x < 0) return false; double tem = 0; int y =x; while(x != 0) { tem = tem*10 + (x%10); x = x/10;

2021-04-09 20:44:11 56

原创 53 -leetcode 7. 整数反转

//看看人家 写的多简单 INT_MIN INT_MAX 2^31 -1 -2^31 7. 整数反转class Solution {public: int reverse(int x) { int fh = 0; if(x == 0) return x; if(x > 0) fh=1; else fh = -1; double x1 = fabs(x); double temp =x1 - ((

2021-04-09 20:22:09 59

原创 53 - leetcode 1. 两数之和 数据结构map类

/* 数据结构类,map 一对一关系类 两者 结构不多 可以用空间 明示了 vector.size 返回类型*/class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { map<int,int> map; vector<int> res; for(int i=0;i < nums.si

2021-04-09 19:22:01 35

原创 54 - 算法 - 动态规划问题 连续子序列和最大

#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <cstdio>#include <cmath>using namespace std;/*问题:动态规划问题 连续子序列和最大 dp[i] = max(dp[i-1]+a[i],a[i]);解决思路:循环 dp[i] 记录当前子序列和最大的值 时间:2021年4月3日23时01分*///宏定义区#define max(x,y

2021-04-08 19:22:17 72

原创 55天 -算法 - poj4137百炼最小新整数 -贪心算法

//模板#include <iostream>#include <cstdio>#include <cstring>using namespace std;/* 1-问题描述:贪心策略 -- poj4137百炼最小新整数 2-解决办法:从前往后每个后面出现比自己小的就 删除当前这个数 注意特殊情况 0 3-时间:2021年4月7日 11时38分*///宏定义区//全局变量数据结构定义区char s[12];.

2021-04-07 11:40:41 165

原创 55天 - 贪心算法 - 田忌赛马问题 openjudge百炼 2287

//模板#include <iostream>#include <cstdio>#include <string>#include <algorithm>using namespace std;/* 1-问题描述:贪心算法 -- 田忌赛马问题 openjudge百炼 2287 2-解决办法:规则 贪心方法策略 从前和后指针数组 3-时间:2021年4月7日 11时19分*///宏定义区#define MA.

2021-04-07 11:20:23 156

原创 55 - 算法 -动态规划 -数塔问题 感觉都是数组建模 递推方法规则

//模板#include <iostream>#include <cstdio>#include <string>using namespace std;/* 1-问题描述:动态规划 -- 数塔问题 2-解决办法:从后往前 用数组表示距离建模 动态规划建模 递推 3-时间:2021年4月7日 10时48分*///全局变量数据结构定义区int Tower[100][100] ={ {9}, {12,15

2021-04-07 10:50:48 73

原创 55天 - 算法 - 动态规划 - 数组类 从前往后

//模板#include <iostream>#include <cstdio>#include <string>using namespace std;/* 1-问题描述:动态规划 -- 最短编辑距离问题 2-解决办法:从前往后 用数组表示距离建模 确认了边界 动态规划建模 递推 相同不变 3-时间:2021年4月7日 10时25分*///全局变量数据结构定义区#define min(x,y) ((x)<(

2021-04-07 10:32:46 82

原创 57 - 算法 -贪心算法 - 区间不相交问题

#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;/*问题:贪心 贪婪算法问题 解决办法 找规则找策略OpenJudge 其他:区间不相交问题leetcode:解决思路:按照右区间从小到大排序

2021-04-05 01:01:51 178

python之knnk近邻算法实现属性为连续性及混淆矩阵评估.zip

python实现了简单的knnk近邻算法,读取的是里面的xlsx文件,最后进行混淆矩阵评估,距离使用的欧式矩阵。

2019-10-25

决策树cart树的实现评估及可视化.rar

代码功能描述:(1)读取第二次xlsx文件,该文件已经人工加上了属性类标签,划分数据集为训练集和测试集 (2)调用相关函数用训练集构造CART树字典 (3)用测试集得到混淆矩阵并且输出正确率 (4)调用相关函数得到该决策树图形

2019-10-18

空空如也

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

TA关注的人

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