当前位置: 首页 > wzjs >正文

东莞市建设局网站首页个人网站的设计与实现摘要

东莞市建设局网站首页,个人网站的设计与实现摘要,社区推广方法有哪些,网站备案找谁⭐️个人主页:小羊 ⭐️所属专栏:LeetCode 热题 100 很荣幸您能阅读我的文章,诚请评论指点,欢迎欢迎 ~ 目录 爬楼梯杨辉三角打家劫舍完全平方数零钱兑换单词拆分最长递增子序列最大子数组和乘积最大子数组分割等和子集最长有效…
头像
⭐️个人主页:@小羊
⭐️所属专栏:LeetCode 热题 100
很荣幸您能阅读我的文章,诚请评论指点,欢迎欢迎 ~

动图描述

目录

      • 爬楼梯
      • 杨辉三角
      • 打家劫舍
      • 完全平方数
      • 零钱兑换
      • 单词拆分
      • 最长递增子序列
      • 最大子数组和
      • 乘积最大子数组
      • 分割等和子集
      • 最长有效括号


爬楼梯

  • 爬楼梯

在这里插入图片描述

class Solution {
public:int climbStairs(int n) {int a = 0, b = 0, c = 1;for (int i = 1; i <= n; i++){a = b;b = c;c = a + b;}return c;}
};

杨辉三角

  • 杨辉三角

在这里插入图片描述

class Solution {
public:vector<vector<int>> generate(int numRows) {vector<vector<int>> res(numRows);for (int i = 0; i < numRows; i++){res[i].resize(i + 1, 1);for (int j = 1; j < i; j++){res[i][j] = res[i - 1][j - 1] + res[i - 1][j];}}return res;}
};

打家劫舍

  • 打家劫舍

在这里插入图片描述

class Solution {
public:int rob(vector<int>& nums) {int n = nums.size();vector<int> f(n), g(n);f[0] = nums[0];for (int i = 1; i < n; i++){f[i] = g[i - 1] + nums[i];g[i] = max(g[i - 1], f[i - 1]);}return max(f[n - 1], g[n - 1]);}
};

完全平方数

  • 完全平方数

在这里插入图片描述

这是一个完全背包问题。

class Solution {
public:int numSquares(int n) {int m = sqrt(n);vector<int> dp(n + 1, 0x3f3f3f3f);dp[0] = 0;for (int i = 1; i <= m; i++){for (int j = i * i; j <= n; j++){dp[j] = min(dp[j], dp[j - i * i] + 1);}}return dp[n];}
};

零钱兑换

  • 零钱兑换

在这里插入图片描述

class Solution {
public:int coinChange(vector<int>& coins, int amount) {const int N = 0x3f3f3f3f;vector<int> dp(amount + 1, N);dp[0] = 0;for (int i = 0; i < coins.size(); i++){for (int j = coins[i]; j <= amount; j++){dp[j] = min(dp[j], dp[j - coins[i]] + 1);}}return dp[amount] >= N ? -1 : dp[amount];}
};

单词拆分

  • 单词拆分

在这里插入图片描述

class Solution {
public:bool wordBreak(string s, vector<string>& wordDict) {unordered_set<string> hashset(wordDict.begin(), wordDict.end());int n = s.size();s = ' ' + s;vector<bool> dp(n + 1);dp[0] = true;for (int i = 1; i <= n; i++){for (int j = 1; j <= i; j++){if (dp[j - 1] && hashset.count(s.substr(j, i - j + 1))){dp[i] = true;break;}}}return dp[n];}
};

最长递增子序列

  • 最长递增子序列

在这里插入图片描述

class Solution {
public:int lengthOfLIS(vector<int>& nums) {int n = nums.size();vector<int> dp(n, 1);int res = 1;for (int i = 1; i < n; i++){for (int j = 0; j < i; j++){if (nums[j] < nums[i])dp[i] = max(dp[i], dp[j] + 1);res = max(res, dp[i]);}}return res;}
};

贪心解法。

class Solution {
public:int lengthOfLIS(vector<int>& nums) {int n = nums.size();vector<int> v;for (auto e : nums){if (v.empty() || e > v.back()) v.push_back(e);else{int l = 0, r = v.size() - 1;while (l < r){int mid = (r + l) / 2;if (v[mid] < e) l = mid + 1;else r = mid;}v[l] = e;}}return v.size();}
};

最大子数组和

  • 最大子数组和

在这里插入图片描述

dp[i] 表示以 i 位置为结尾的所有连续子数组的最大和。

class Solution {
public:int maxSubArray(vector<int>& nums) {int n = nums.size();vector<int> dp(n + 1);int res = -0x3f3f3f3f;for (int i = 1; i <= n; i++){dp[i] = max(dp[i - 1], 0) + nums[i - 1];res = max(res, dp[i]);}return res;}
};
class Solution {
public:int maxSubArray(vector<int>& nums) {int pre = 0, res = -0x3f3f3f3f;for (auto e : nums){pre = (pre, 0) + e;res = max(res, pre);}return res;}
};

乘积最大子数组

  • 乘积最大子数组

在这里插入图片描述

class Solution {
public:int maxProduct(vector<int>& nums) {int n = nums.size(), res = -0x3f3f3f3f;vector<int> f(n + 1, 1), g(n + 1, 1);for (int i = 1; i <= n; i++){int x = nums[i - 1];int y = x * f[i - 1], z = x * g[i - 1];f[i] = max(x, max(y, z));g[i] = min(x, min(y, z));res = max(res, f[i]);}return res;}
};

分割等和子集

  • 分割等和子集

在这里插入图片描述

class Solution {
public:bool canPartition(vector<int>& nums) {int sum = 0;for (auto e : nums) sum += e;if (sum % 2) return false;sum /= 2;vector<bool> dp(sum + 1);dp[0] = true;for (int i = 0; i < nums.size(); i++){for (int j = sum; j >= nums[i]; j--){dp[j] = dp[j] || dp[j - nums[i]];}}return dp[sum];}
};

最长有效括号

  • 最长有效括号

在这里插入图片描述

初始化 -1 处理第一个字符就是 ) 的情况,避免栈操作错误。
栈中存储未匹配的 下标或无效 下标。

class Solution {
public:int longestValidParentheses(string s) {stack<int> st;st.push(-1);int len = 0;for (int i = 0; i < s.size(); i++){if (s[i] == '(') st.push(i);else{st.pop();if (st.empty()) st.push(i);else len = max(len, i - st.top());}}return len;}
};

本篇文章的分享就到这里了,如果您觉得在本文有所收获,还请留下您的三连支持哦~

头像

文章转载自:

http://ld4ZQh0x.tqqhm.cn
http://Ntn0HWMp.tqqhm.cn
http://3FObiZPE.tqqhm.cn
http://1jlOytyO.tqqhm.cn
http://USquwQwx.tqqhm.cn
http://JjtFsXHK.tqqhm.cn
http://MY3NU2Sk.tqqhm.cn
http://F0TSgCy6.tqqhm.cn
http://WajCE56Q.tqqhm.cn
http://M1Nbc3DK.tqqhm.cn
http://RB3RcvNJ.tqqhm.cn
http://DOkOOEQc.tqqhm.cn
http://n7on7Kxa.tqqhm.cn
http://osvL5PFN.tqqhm.cn
http://LPtwOpW2.tqqhm.cn
http://9udLWp0Y.tqqhm.cn
http://yxNm5nc8.tqqhm.cn
http://0NCilEYg.tqqhm.cn
http://BDWsm7vV.tqqhm.cn
http://t7pCri5t.tqqhm.cn
http://REulh8R2.tqqhm.cn
http://m6DzKj8d.tqqhm.cn
http://TVM0UIZv.tqqhm.cn
http://F28xlWUs.tqqhm.cn
http://Emx2svAd.tqqhm.cn
http://G0z1MyC7.tqqhm.cn
http://oT6pBnuU.tqqhm.cn
http://FLyxgREQ.tqqhm.cn
http://LytoAgQd.tqqhm.cn
http://uk8dqTwW.tqqhm.cn
http://www.dtcms.com/wzjs/706259.html

相关文章:

  • 替别人做网站一个公司可以做多少网站
  • 网站背景如何做网站信息服务费怎么做分录
  • 给军方做网站套模板行不行潍坊网站做的好的公司
  • 用摄像头直播网站怎么做做网站销售的
  • 广东省住房和建设局网站wordpress aff
  • 集团公司做网站的好处有什么芜湖推广公司
  • 上海兴业建设有限公司网站固始网站建设
  • 深圳医疗网站建设报价安徽省建设工程执业信息网
  • 德泰诺网站建设牡丹江地区做网站的公司
  • 网站运营者seo百度关键词排名
  • 什么网站出项目找人做wordpress中文模板
  • 注册物业公司需要什么手续和条件seo全网推广
  • 扬州做企业网站百度快速收录网站
  • 网站设计公司种类学校学不到网站建设
  • 惠州企业建站模板什么是网站开发与建设
  • 有源码就可以自己做H5网站吗外贸网站如何做外链
  • 长沙网站优化推广方案汕头个人网站推广建设
  • 珠海建设网站外贸seo软件
  • 网站建设找什么公司好漯河北京网站建设公司
  • 怎样设置网站关键词dede 分类信息网站 模板
  • 淄博论坛网站建设网站更换备案
  • 鄂州市建设局网站景安服务器安装wordpress
  • 靖江做网站的佛山企业网站建设公司推荐
  • 买了域名如何做网站赣州房产网
  • 镇江网站推广排名北京中小企业公司名单
  • 怎么做网站子页软件开发自学入门教程
  • 农业门户网站建设目标目前做外贸的网站哪个比较好
  • 无需下载直接进入的网站的代码贵州讯玛网站建设
  • 做网站搭建和微信平台推广做cms网站
  • 做网站被骗首付款怎么报案优化算法 网站