自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 以反转链表为例的链表初始化

#include <iostream>//迭代法class Node{public: int value; Node* next; Node(int data){ this->value = data; }} ;Node* reverseNode(Node* head){ Node* pre = head; Node* cur = NULL; while(pre!=NULL) { Node* tem = pre->next.

2022-04-16 23:00:43 820

原创 平面拟合2

1.直接法 直接求解超定方程。 我们知道,对于一个平面,其方程可以用来表示。由离散点拟合平面,实际上就是求解超定方程:上述方程可以用来表示。由于A是一个的矩阵,因此我们先在等号两边分别乘以A的转置矩阵,使系数矩阵变为的方阵,之后,通过乘以系数矩阵的逆矩阵求解,也就是说,。import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3D # 创建函数,用于生成..

2022-04-16 22:53:16 953

原创 直线拟合1

直线拟合1.点到直线的误差平方和+分别对其关于k和b求导. y=kx+bvoid LineFitLeastSquares(float *data_x, float *data_y, int data_n) { float A = 0.0; float B = 0.0; float C = 0.0; float D = 0.0; float E = 0.0; float F = 0.0; fo.

2022-04-16 22:43:39 344

原创 3.19京东笔试

分鸡蛋#include <iostream>using namespace std;int sum(int a, int y){ if(a==y) return 0; if(a % 3==0){ return sum(a/3, y) + 1; }else{ return sum(a+1, y) + 1; }}int main (){ int x, y; cin >> x >> y

2022-03-19 22:35:51 438

原创 C++定义单链表节点

struct ListNode{ int val; ListNode* next; ListNode(int x) : val(x), next(NULL) {} // 节点的构造函数};或者使用默认构造函数初始化链表ListNode* head = new ListNode();head->val = 5;

2022-03-18 11:38:44 1492

原创 快排 模版

#include <iostream>#include <vector>using namespace std;int partition(vector<int>& nums, int start, int end){ int idx = start + rand()%(end-start+1); swap(nums[start], nums[idx]); int pivot = nums[start]; in.

2022-03-03 20:03:19 90

原创 力扣剑指offer第17天 树

47)二叉树剪枝class Solution {public: TreeNode* pruneTree(TreeNode* root) { if(root->left) root->left = pruneTree(root->left); if(root->right) root->right = pruneTree(root->right); if(root->left==nullptr &&

2022-02-04 22:28:55 6851

原创 力扣剑指offer第22天 前缀和

65)最短的单词编码class Solution {public: int minimumLengthEncoding(vector<string>& words) { unordered_set<string> good(words.begin(), words.end()); for(auto word : words){ for(int k=1; k<word.size(); k++){

2022-02-04 21:45:54 239

原创 力扣剑指offer第21天 前缀树

62)实现前缀树class Solution{private: bool isWord; vector<Trie*> children; Trie* isSearch(string word){ Trie* node = this; for(const char& ch : word){ if(node->children[ch-'a'] == nullptr) return nullptr;

2022-02-04 13:56:44 144

原创 力扣剑指offer第20天 堆

59)数据流的第 K 大数值class KthLargest{private: int k; priority_queue<int, vector<int>, greater<int>> q;public: KthLargest(int k, vector<int> nums){ this->k = k; for(auto num : nums){ add(num

2022-02-03 21:50:45 273

原创 力扣剑指offer第19天

class Solution {public: bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) { int n = nums.size(); set<int> ret; for(int i=0; i<nums.size(); i++){ auto iter = ret.lower_bound(max(nums[i], I.

2022-02-03 21:11:39 246

原创 力扣剑指offer第18天 树

53)二叉搜索树中的中序后继class Solution {public: TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) { TreeNode* res = nullptr; TreeNode* cur = root; while(cur){ if(cur->val > p->val){ res = cur;

2022-02-03 20:34:37 330

原创 力扣剑指offer第17天 树

50)向下的路径节点之和class Solution{public: int pathSum(TreeNode* root, int targetSum){ if(!root) return 0; int ret = rootSum(root, targetSum); ret += pathSum(root->left, targetSum); ret += pathSum(root->right, targetSu

2022-02-03 19:36:28 134

原创 剑指offer第15天 队列

44)二叉树每层的最大值class Solution {public: vector<int> largestValues(TreeNode* root) { queue<TreeNode*> q; q.push(root); vector<int> res; if(root==nullptr) return res; while(q.size()>0){ int len =

2022-02-03 16:58:07 43

原创 力扣剑指offer第14天 队列

41)滑动窗口的平均值class MovingAverage {private: queue<int> q; int win; double sum = 0;public: /** Initialize your data structure here. */ MovingAverage(int size) { win = size; } double next(int val) { q.push(val);

2022-01-30 12:16:21 4760

原创 力扣剑指offer第13天 栈

39)直方图最大矩形面积class Solution {public: int largestRectangleArea(vector<int>& heights) { stack<int> s; int res=0; heights.push_back(0); for(int i=0; i<heights.size(); i++){ while(!s.empty() &&

2022-01-29 18:51:21 117

原创 力扣剑指offer第12天 栈

36)后缀表达式class Solution {public: int evalRPN(vector<string>& tokens) { if(tokens.empty()) return 0; stack<int> stk; int res; for(int i=0; i<tokens.size(); i++){ if(tokens[i]=="+" || tokens[i]=="-" |

2022-01-29 18:08:04 285

原创 力扣剑指offer第11天 哈希表

33)变位词组class Solution {public: vector<vector<string>> groupAnagrams(vector<string>& strs) { vector<vector<string>> res; unordered_map<string, vector<string>> hash; for(auto str : strs)

2022-01-28 18:44:02 577

原创 力扣剑指offer第10天 哈希表

30)插入、删除和随机访问都是 O(1) 的容器class RandomizedSet {public: /** Initialize your data structure here. */ unordered_map<int, int> nums_idx; vector<int> nums; RandomizedSet() { } /** Inserts a value to the set. Returns t

2022-01-27 20:10:20 471

原创 力扣剑指offer第9天链表

27)回文链表class Solution{public: ListNode* reverseList(ListNode* l){ if(!l || !l->next) return l; ListNode* newl = reverseList(l->next); l->next->next = l; l->next = nullptr; return newl; }

2022-01-26 19:20:31 216

原创 力扣剑指offer第8天链表

24)反转链表迭代法class Solution{public: ListNode* reverseList(ListNode* head){ ListNode* pre = nullptr, *cur = head; while(cur){ ListNode *temp = cur->next; cur->next = pre; pre = cur;

2022-01-26 11:25:34 230

原创 力扣剑指offer第7天

21)删除链表的倒数第 n 个结点/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next)

2022-01-23 13:56:40 434

原创 力扣剑指offer第6天字符串

17)含有所有字符的最短字符串class Solution {public: string minWindow(string s, string t) { unordered_map<char, int> hs, ht; string ans; for(auto& ch : t) ht[ch]++; int left=0, cnt=0; for(int right=0; right<s.size(); ri

2022-01-23 12:47:15 208

原创 力扣剑指offer第5天字符串

14)字符串中的变位词class Solution {public: bool checkInclusion(string s1, string s2) { int m=s1.size(), n=s2.size(); if(m>n) return false; vector<int> vec(26); for(int i=0; i<m; i++){ vec[s1[i]-'a']++; }

2022-01-22 11:48:44 233

原创 力扣剑指offer第4天数组

class Solution {public: int subarraySum(vector<int>& nums, int k) { int n = nums.size(); int ans = 0; vector<int> prev(n+1); prev[0] = 0; for(int i=1; i<=n; i++){ prev[i] = prev[i-1] + nums[i-1.

2022-01-21 17:23:12 401

原创 力扣剑指offer2第3天

7)数组中和为 0 的三个数class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> res; int n = nums.size(); if(n<3) return res; sort(nums.begin(), nums.end());

2022-01-21 15:57:47 255

原创 力扣剑指offer2第2天整数

4)只出现一次的数字class Solution{public: int singleNumber(vector<int>& nums){ int ans = 0; for(int i=0; i<=31; i++){ int total = 0; for(int num : nums){ total += ((num>>i)&1);.

2022-01-20 23:20:13 123

原创 力扣剑指offer2第1天整数

1)剑指 Offer II 001. 整数除法class Solution{public: int divide(int a, int b){ if(a==INT_MIN && b==-1) return INT_MAX; int flag = (a>0)^(b>0) ? -1 : 1; unsigned int ua = abs(a); unsigned int ub = abs(b);

2022-01-20 17:30:15 337

原创 力扣剑指offer2第40天图

117)相似的字符串class Solution {public: vector<int> f; int find(int x){ return f[x]==x ? x : find(f[x]); } bool check(string &a, string &b, int len){ int num = 0; for(int i=0; i<len; i++){

2022-01-09 21:30:17 212

原创 力扣剑指offer第39天图

114)外星人字典class Solution{public: int startsWith(string s, string sub){ return s.find(sub) == 0 ? 1 : 0; } string alienOrder(vector<string>& words){ unordered_map<char, unordered_set<char>> graph;

2022-01-08 17:25:14 3199

原创 力扣剑指offer2第38天图

111)计算除法class Solution{public: vector<double> calcEquation(vector<vector<string>>& equations, vector<double>& values, vector<vector<string>>& queries){ int nvars = 0; unordered_map<

2022-01-07 15:53:58 407

原创 力扣剑指offer2第37tian 图

108)单词演变class Solution{public: int ladderLength(string beginWord, string endWord, vector<string>& wordList){ unordered_set<string> s; for(auto &i : wordList) s.insert(i); queue<pair<string, int>

2022-01-06 15:42:18 36

原创 力扣剑指offer2第36天图

105)岛屿的最大面积dfsclass Solution{public: int maxAreaOfIsland(vector<vector<int>>& grid){ int res = 0; int m = grid.size(), n = grid[0].size(); for(int i=0; i<m; i++){ for(int j=0; j<n; j++){

2022-01-05 16:07:45 226

原创 力扣剑指offer2第35天

103)最少的硬币数目class Solution{public: int coinChange(vector<int>& coins, int amount){ vector<int> dp(amount+1, amount+1); dp[0]=0; for(int i=1; i<=amount; i++){ for(int coin : coins){

2022-01-04 15:19:20 436

原创 力扣剑指offer2第33天动态规划

97)子序列的数目class Solution{public: int numDistinct(){

2022-01-03 22:14:26 27

原创 力扣剑指offer第34天动态规划

100)三角形中最小路径之和从下到上,不占其他空间class Solution{public: int minimumTotal(vector<vector<int>>& triangle){ for(int i=triangle.size()-2; i>=0; i--){ for(int j=0; j<=i; j++){ triangle[i][j] = min(tria

2022-01-03 21:47:08 323

原创 力扣剑指offer2第32天动态规划

94)最少回文分割class Solution{public: int minCut(string s){ int n = s.size(); vector<vector<int>> g(n, vector<int>(n, true)); for(int i=n-1; i>=0; i--){ for(int j=i+1; j<n; j++){

2022-01-02 19:24:26 160

原创 力扣剑指offer2第31天动态规划

91)粉刷房子二维dpclass Solution{public: int minCost(vector<vector<int>>& costs){ int n = costs.size(); vector<vector<int>> f(n+1, vector<int>(costs[0].size(), 0)); for(int i=1; i<=n; i++){

2021-12-31 15:58:20 472

原创 力扣剑指offer2第30天动态规划

88)爬楼梯的最少成本first=cost[0], second=cost[1];class Solution{public: int minCostClimbingStairs(vector<int>& cost){ int n = cost.size(); int first = cost[0]; int second = cost[1]; for(int i=2; i<cost.siz

2021-12-30 14:58:27 174

原创 力扣剑指offer2第29天回溯法

85)生成匹配的括号纯纯的dfsclass Solution{public: vector<string> res; vector<string> generateParenthesis(int n){ dfs(n, 0, 0, ""); return res; } void dfs(int n, int left, int right, string str){ if(left==n &am

2021-12-30 13:57:29 174

空空如也

空空如也

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

TA关注的人

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