算法与数据结构
Rong_Jie
这个作者很懒,什么都没留下…
展开
-
最长不含重复字符的子串
最长不含重复字符的子串请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度。示例 1:输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。示例 2:输入: "bbbbb"输出: 1解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。示例 3:输入: "pwwkew"输出: 3解释: 因为无重复字符的最长子串是 "wke",所以其长度为 3。 请注意,你的答案必须是 子串 的长度,"原创 2021-05-25 23:28:59 · 217 阅读 · 0 评论 -
动态规划(三)最长公共子序列(LCS)
最长公共子序列#include <iostream>#include "string"#include<vector>using namespace std;// 状态:dp[i][j] 表示s1中第i个字符和s2中第j个字符表示的最长公共子序列// 状态转移:dp[i][j] = max(dp[i-1][j], dp[i][j-1])int lcs(const string &s1, const string &s2) { if (s1.len原创 2021-05-21 23:42:08 · 62 阅读 · 0 评论 -
动态规划(二)0-1背包问题
0-1背包问题递归+记忆中间结果#include <iostream>#include "string"#include<vector>using namespace std;int backage01(vector<int> w, vector<int> v, int contains, int index);vector<vector<int>> memory;int backage01(vector<int&原创 2021-05-21 01:01:19 · 72 阅读 · 0 评论 -
动态规划(一)正整数拆解问题
问题描述动态规划问题总结问题leetcode 343. Integer BreakGiven an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.Return the maximum product you can get.Example 1:Input: n = 2Output: 1Explanatio原创 2021-05-18 23:43:13 · 154 阅读 · 0 评论 -
图搜索问题(二)N皇后(leetcode 51)&数独(leetcode 37)
N皇后leetcode 51The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each solution contains a distinct board confi原创 2021-05-15 11:21:34 · 49 阅读 · 0 评论 -
图搜索问题(一)字符串匹配(leetcode 79)&连接图判断(leetcode 200)
图的深度遍历leetcode 79. Word SearchGiven an m x n grid of characters board and a string word, return true if word exists in the grid.The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically原创 2021-05-11 08:43:35 · 159 阅读 · 0 评论 -
排列组合问题
排列问题:leetcode 46. Permutations.Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.Example 1:Input: nums = [1,2,3]Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]代码实现class原创 2021-05-09 23:37:14 · 75 阅读 · 0 评论 -
二叉树前序\中序\后序\层次遍历
节点信息struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(0), left(nullptr), right(nullptr) {} TreeNode(int x) :val(0), left(nullptr), right(nullptr) {} TreeNode(int x, TreeNode *left, TreeNode *right) : val(原创 2021-04-18 13:34:15 · 57 阅读 · 0 评论 -
红黑树,算法导论
RB Tree本文将理解红黑树的性质,红黑树的插入、删除操作的源码及时间复杂度分析。性质所有结点只有红、黑两色根结点是黑色任意节点到叶子结点的所有路径中还有的黑色结点的个数(黑高(hb(x))相同叶子结点(nil)都为黑色红色结点的孩子结点一定是黑色左旋左右旋转结点是红黑树的插入和删除的基础操作。下面将给出左旋操作,右旋操作类似。LEFT-ROTATE(T, x) y...原创 2019-07-15 12:00:05 · 150 阅读 · 0 评论 -
十大排序算法(C++版)
排序算法冒泡排序#include <bits/stdc++.h>using namespace std;//时间复杂度 最好的:O(n^2), 最坏:O(n^2),平均:O(n^2),空间复杂度:O(1),稳定//改善的冒泡排序 最好:O(n) 最好 O(n^2) 平均 O(n^2)void bubble(int a[],int length){ for(int...原创 2019-07-04 12:12:35 · 125 阅读 · 0 评论