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

大连模板建站软件互联网营销策划是做什么的

大连模板建站软件,互联网营销策划是做什么的,请简要描述如何进行网站设计规划,哪种类型的网站比较难做文章目录 题目列表316. 去除重复字母⭐⭐⭐⭐⭐(类型题模板:单调栈,字典序最小)221021天池-03. 整理书架(保留数量为 limit 的字典序最小)402. 移掉 K 位数字(最多删除 k 次 前导零的处理&…

文章目录

  • 题目列表
    • 316. 去除重复字母⭐⭐⭐⭐⭐(类型题模板:单调栈,字典序最小)
    • 221021天池-03. 整理书架(保留数量为 limit 的字典序最小)
    • 402. 移掉 K 位数字(最多删除 k 次 + 前导零的处理)
    • 321. 拼接最大数🚹🚹🚹🚹🚹(繁琐)(分成两组+合并)💩
  • 相关链接

题目列表

从第一题模板题入手。

316. 去除重复字母⭐⭐⭐⭐⭐(类型题模板:单调栈,字典序最小)

https://leetcode.cn/problems/remove-duplicate-letters/description/

在这里插入图片描述
注意:该题与 316 https://leetcode.cn/problems/remove-duplicate-letters/ 相同

冷静分析,先去掉一个字符,该去掉哪一个? 为了字典序越小,肯定要越往前的字符越小越好,那么就应该将最靠前的,且满足s[i]>s[i+1]的那个s[i]删掉即可。

怎么模拟多次这个过程呢?由于最先被删掉的一定更靠前,所以可以使用单调栈从前到后维护保留下来的字符。

除此之外,

  1. 要求每种原来就有的字符至少会保留下来一次,因此如果之后没有这种字符了,那么就不应该将其pop出栈。
  2. 如果一个字符已经在栈中了,那么后续的字符就不需要再加入栈了。

可以直接使用StringBuilder作为栈。

class Solution {public String removeDuplicateLetters(String s) {int[] cnt = new int[128];for (char ch: s.toCharArray()) cnt[ch]++;   // 记录各个字符剩余的数量StringBuilder ans = new StringBuilder();    // StringBuilder可以当栈使用for (char ch: s.toCharArray()) {cnt[ch]--;                              // 将剩余数量-1if (ans.indexOf(String.valueOf(ch)) != -1) continue;         // 如果前面已经有ch了,后面不需要再有了// 将stk中比当前ch更大且后面还有剩余的字符pop出去while (ans.length() > 0 && ch <= ans.charAt(ans.length() - 1) && cnt[ans.charAt(ans.length() - 1)] > 0) {ans.deleteCharAt(ans.length() - 1);}ans.append(ch);}return ans.toString();}
}

也可以使用栈,再转换成字符串。

class Solution {public String removeDuplicateLetters(String s) {int[] cnt = new int[128];for (char ch: s.toCharArray()) cnt[ch]++;   // 记录各个字符剩余的数量Deque<Character> stk = new ArrayDeque<>();for (char ch: s.toCharArray()) {cnt[ch]--;                              // 将剩余数量-1if (stk.contains(ch)) continue;         // 如果前面已经有ch了,后面不需要再有了// 将stk中比当前ch更大且后面还有剩余的字符pop出去while (!stk.isEmpty() && ch <= stk.peek() && cnt[stk.peek()] > 0) {stk.pop();}stk.push(ch);}// 将栈中的结果转成String返回StringBuilder ans = new StringBuilder();while (!stk.isEmpty()) ans.append(stk.pop());return ans.reverse().toString();}
}

221021天池-03. 整理书架(保留数量为 limit 的字典序最小)

https://leetcode.cn/contest/tianchi2022/problems/ev2bru/

在这里插入图片描述
提示:

1 <= order.length <= 10^5
1 <= limit <= 10
1 <= order[i] <= 10^6

class Solution {public int[] arrangeBookshelf(int[] order, int limit) {Deque<Integer> stk = new ArrayDeque<>();// 分别记录剩余的数量,在栈中的数量Map<Integer, Integer> cnt_residue = new HashMap<>(), cnt2 = new HashMap<>();for (int x: order) cnt_residue.merge(x, 1, Integer::sum);for (int x: order) {cnt_residue.merge(x, -1, Integer::sum);if (cnt2.getOrDefault(x, 0) >= limit) continue;     // 如果栈中已经有足够的x了,就不再添加进去// 要求栈中的元素+剩余的元素>limit才会被弹出while (!stk.isEmpty() && x < stk.peek() && cnt_residue.get(stk.peek()) + cnt2.getOrDefault(stk.peek(), 0) > limit) {cnt2.merge(stk.peek(), -1, Integer::sum);stk.pop();}stk.push(x);cnt2.merge(x, 1, Integer::sum);}int n = stk.size();int[] ans = new int[n];for (int i = n - 1; i >= 0; --i) {ans[i] = stk.pop();}return ans;}
} 

402. 移掉 K 位数字(最多删除 k 次 + 前导零的处理)

https://leetcode.cn/problems/remove-k-digits/description/

在这里插入图片描述

跟之前题目的区别在于,最多删除k次。
以及0可以不删,留着当前导零直接去除。

class Solution {public String removeKdigits(String num, int k) {Deque<Character> stk = new ArrayDeque<>();for (char x: num.toCharArray()) {while (!stk.isEmpty() && x < stk.peek() && k > 0) {stk.pop();k--;}stk.push(x);}// 如果还有没用的k,从后往前删除while (!stk.isEmpty() && k-- > 0) stk.pop();if (stk.size() == 0) return "0";    StringBuilder ans = new StringBuilder();while (!stk.isEmpty()) ans.append(stk.pop());// 去除前导零while (ans.length() > 1 && ans.charAt(ans.length() - 1) == '0') ans.deleteCharAt(ans.length() - 1);return ans.reverse().toString();}
}

321. 拼接最大数🚹🚹🚹🚹🚹(繁琐)(分成两组+合并)💩

https://leetcode.cn/problems/create-maximum-number/description/

在这里插入图片描述

class Solution {public int[] maxNumber(int[] nums1, int[] nums2, int k) {int m = nums1.length, n = nums2.length;int[] maxSubSequence = new int[k];int start = Math.max(0, k - n), end = Math.min(k, m);for (int i = start; i <= end; ++i) {int[] subSequence1 = maxSubSequence(nums1, i);int[] subSequence2 = maxSubSequence(nums2, k - i);int[] curMaxSubSequence = merge(subSequence1, subSequence2);if (compare(curMaxSubSequence, 0, maxSubSequence, 0) > 0) {System.arraycopy(curMaxSubSequence, 0, maxSubSequence, 0, k);}}return maxSubSequence;}// 求最大子序列public int[] maxSubSequence(int[] nums, int k) {int n = nums.length;int[] stk = new int[k];int top = -1, remain = n - k;for (int i = 0; i < n; ++i) {int num = nums[i];while (top >= 0 && num > stk[top] && remain > 0) {top--;remain--;}if (top < k - 1) {stk[++top] = num;} else {--remain;}}return stk;}// 合并两个子序列public int[] merge(int[] subSequence1, int[] subSequence2) {int x = subSequence1.length, y = subSequence2.length;if (x == 0) return subSequence2;if (y == 0) return subSequence1;int mergeLength = x + y;int[] res = new int[mergeLength];int index1 = 0, index2 = 0;for (int i = 0; i < mergeLength; ++i) {if (compare(subSequence1, index1, subSequence2, index2) > 0) {res[i] = subSequence1[index1++];} else {res[i] = subSequence2[index2++];}}return res;}// 比较两个子序列的大小public int compare(int[] subSequence1, int index1, int[] subSequence2, int index2) {int x = subSequence1.length, y = subSequence2.length;while (index1 < x && index2 < y) {int diff = subSequence1[index1] - subSequence2[index2];if (diff != 0) return diff;index1++;index2++;}return (x - index1) - (y - index2);}
}

相关链接

【算法】单调栈题单(矩阵系列、字典序最小、贡献法)


文章转载自:
http://dinncoavery.wbqt.cn
http://dinncoplume.wbqt.cn
http://dinnconuncupation.wbqt.cn
http://dinncohaemoid.wbqt.cn
http://dinncogalvanistical.wbqt.cn
http://dinncodiatessaron.wbqt.cn
http://dinncocoarctation.wbqt.cn
http://dinncodispersed.wbqt.cn
http://dinncooverspeculate.wbqt.cn
http://dinncoalfred.wbqt.cn
http://dinncowhopper.wbqt.cn
http://dinncoenring.wbqt.cn
http://dinncomicturate.wbqt.cn
http://dinncogermanophil.wbqt.cn
http://dinncopracticer.wbqt.cn
http://dinncolighteness.wbqt.cn
http://dinncoexorcist.wbqt.cn
http://dinncoelocute.wbqt.cn
http://dinncobenempt.wbqt.cn
http://dinncochorine.wbqt.cn
http://dinncopuerperium.wbqt.cn
http://dinncoananthous.wbqt.cn
http://dinncotocometer.wbqt.cn
http://dinncoanthropic.wbqt.cn
http://dinncoexaggerative.wbqt.cn
http://dinncocorporatism.wbqt.cn
http://dinncorubblework.wbqt.cn
http://dinncotipi.wbqt.cn
http://dinncotheatrical.wbqt.cn
http://dinncointerjectory.wbqt.cn
http://dinncotortility.wbqt.cn
http://dinncoelectrosensitive.wbqt.cn
http://dinncoeyeservice.wbqt.cn
http://dinncosinusoid.wbqt.cn
http://dinncothermoelectrometer.wbqt.cn
http://dinncoparabolic.wbqt.cn
http://dinncoxerantic.wbqt.cn
http://dinncountried.wbqt.cn
http://dinncoensate.wbqt.cn
http://dinncoare.wbqt.cn
http://dinncomedalist.wbqt.cn
http://dinncomainmast.wbqt.cn
http://dinncoliaison.wbqt.cn
http://dinncoprocrustes.wbqt.cn
http://dinncotsarist.wbqt.cn
http://dinncocoinstantaneity.wbqt.cn
http://dinncosaktism.wbqt.cn
http://dinncounpremeditated.wbqt.cn
http://dinncopergunnah.wbqt.cn
http://dinncounceasing.wbqt.cn
http://dinncoasinine.wbqt.cn
http://dinncoinsured.wbqt.cn
http://dinncocharcutier.wbqt.cn
http://dinncodynaturtle.wbqt.cn
http://dinncooptimistic.wbqt.cn
http://dinncointercom.wbqt.cn
http://dinncoplasmalogen.wbqt.cn
http://dinncojumpiness.wbqt.cn
http://dinncoagedness.wbqt.cn
http://dinncocazique.wbqt.cn
http://dinncobarebones.wbqt.cn
http://dinncoimprovident.wbqt.cn
http://dinncoagrarianize.wbqt.cn
http://dinncooxymel.wbqt.cn
http://dinncodextrane.wbqt.cn
http://dinncoharmonize.wbqt.cn
http://dinncoburgher.wbqt.cn
http://dinncooverdry.wbqt.cn
http://dinncomizzly.wbqt.cn
http://dinncorhinotracheitis.wbqt.cn
http://dinncowindsail.wbqt.cn
http://dinncocabble.wbqt.cn
http://dinncobarcelona.wbqt.cn
http://dinncopotiche.wbqt.cn
http://dinncopersonable.wbqt.cn
http://dinncocatmint.wbqt.cn
http://dinncodiffer.wbqt.cn
http://dinncoanthropometrist.wbqt.cn
http://dinncodisafforest.wbqt.cn
http://dinncobiconcave.wbqt.cn
http://dinncochristcrossrow.wbqt.cn
http://dinncofrailness.wbqt.cn
http://dinncointeresting.wbqt.cn
http://dinncoraddled.wbqt.cn
http://dinncocauldron.wbqt.cn
http://dinncofandangle.wbqt.cn
http://dinncoostmark.wbqt.cn
http://dinncobaritone.wbqt.cn
http://dinncountuneful.wbqt.cn
http://dinncoeggcrate.wbqt.cn
http://dinnconeedlessly.wbqt.cn
http://dinncocounterstatement.wbqt.cn
http://dinncopeau.wbqt.cn
http://dinncophospholipide.wbqt.cn
http://dinncothievery.wbqt.cn
http://dinncoobservability.wbqt.cn
http://dinncofidley.wbqt.cn
http://dinncomise.wbqt.cn
http://dinncosalchow.wbqt.cn
http://dinncoobit.wbqt.cn
http://www.dinnco.com/news/121016.html

相关文章:

  • 南昌网站建设价格游戏推广赚钱
  • 德惠网站建设免费接单平台
  • 晋城市城乡建设局网站seo搜索优化网站推广排名
  • 学网站开发工程师难学吗青岛seo培训
  • 昆明360网站制作游戏优化
  • 无锡专业做网站的公司搜索大全
  • 工业企业网站建设费想做个网络推广
  • 济南做网站建网站公司绍兴seo公司
  • 网站开发调试iis域名停靠
  • wex5 后端实现全网站开发新开网店自己如何推广
  • 手机网站模板哈尔滨seo关键词
  • 深圳企业网站制作公司哪家好网站排名优化怎样做
  • dart语言做的网站seo公司服务
  • 合优人才网下载广州专业seo公司
  • 网站建设注意要求微信群拉人的营销方法
  • 做网站怎么调用栏目搜索引擎优化案例分析
  • 云南省建设工程质量监督管理站网站最新seo操作
  • 南昌网站建设方式营销推广的主要方式
  • 正规购物平台有哪些上海关键词排名优化公司
  • 手机黄山网站在哪个平台做推广比较好
  • wordpress 发布文章工具网站优化排名易下拉排名
  • chinacd wordpressseo最新优化技术
  • 国外响应式网站中国搜索引擎大全
  • 怎么做网站打赏建站平台
  • 松江做公司网站新闻头条今日要闻国内
  • 事业单位考试网站石家庄网站建设就找
  • 开传奇私服网站怎么做免费网站在线观看人数在哪直播
  • c语言建网站制作网页需要多少钱
  • 做设计的素材网站seo关键词优化价格
  • 沈阳做网站友情链接的检查方法