哪些行业做网站最重要,国外做二手服装网站有哪些问题,大鱼号自媒体平台注册,网站的建设方法包括什么作用目录 1633. 各赛事的用户注册率题目链接表要求知识点思路代码 122. 买卖股票的最佳时机 II题目链接标签思路代码 239. 滑动窗口最大值题目链接标签思路代码 1633. 各赛事的用户注册率 
题目链接 
1633. 各赛事的用户注册率 
表 
表Users有字段user_id和user_name。表Register有… 目录 1633. 各赛事的用户注册率题目链接表要求知识点思路代码 122. 买卖股票的最佳时机 II题目链接标签思路代码 239. 滑动窗口最大值题目链接标签思路代码  1633. 各赛事的用户注册率 
题目链接 
1633. 各赛事的用户注册率 
表 
表Users有字段user_id和user_name。表Register有字段contest_id和user_id。 
要求 
编写解决方案统计出各赛事的用户注册百分率保留两位小数。返回的结果表按 percentage 的 降序 排序若相同则按 contest_id 的 升序 排序。 
知识点 
rount()四舍五入函数。count()统计个数函数。多表查询from后跟多张表然后使用where限制笛卡尔积的部分数据多表查询的结果是两张表排列组合的结果这个结果被称为笛卡尔积。子表查询子表查询就是将从表查询到的结果作为另一个表放在from后边。order by  desc/asc排序比如order by num表示按num进行默认升序排序效果等价于order by num ascorder by num desc表示按num进行降序排序。 
思路 
要求各赛事的用户注册百分率首先要求出参加各赛事的用户数和用户的总数求用户的总数可以键一张子表然后用前者除以后者就可以得出各赛事的用户注册百分率但要注意的是求出来的百分率要乘100然后再根据题目中的两个条件进行排序。 
代码 
selectcontest_id,round(count(*) * 100 / cnt.num, 2) percentage
fromUsers s,Register r,(selectcount(*) numfromUsers) cnt
wheres.user_id  r.user_id
group bycontest_id
order bypercentage desc,contest_id122. 买卖股票的最佳时机 II 
题目链接 
122. 买卖股票的最佳时机 II 
标签 
贪心 数组 动态规划 
思路 
本题的股票可以随时卖和买所以不需要计划的很长远只要一天的价格比前一天的高就在前一天买然后在这天卖使用了一种贪心的思想只顾当前局部的最优解局部最优解的总和就是全局最优解。 
代码 
class Solution {public int maxProfit(int[] prices) {int i  1, res  0;while (i  prices.length) {int profit  prices[i] - prices[i - 1];if (profit  0) {res  profit;}i;}return res;}
}239. 滑动窗口最大值 
题目链接 
239. 滑动窗口最大值 
标签 
队列 数组 滑动窗口 单调队列 堆优先队列 
思路 
本题建议使用优先队列来解答优先队列指的是插入队列的所有元素都有一个优先级按照优先级的大小进行排序优先级越大或越小越靠近队列头部或尾部其中优先级可以是数字的大小也可以是字符串的长度等可以量化的数量。 优先队列的实现也很简单在这个类中内置一个双端队列从头部执行获取和删除的操作从尾部执行添加的操作每次添加时从尾部向前扫描直到扫描到优先级比待添加元素的优先级高的元素将这些优先级低于待添加元素优先级的元素从队列中删除。 了解优先队列的实现后就可以开始做题了。把滑动窗口想象成一个优先队列每次滑动时都往队列中添加一个值按理来说也应该从队列中删除一个值但其实不然在这个优先队列中只有最大值会被使用到所以只要那个该删除的值不是最大值就不需要删除它。 
代码 
class Solution {public int[] maxSlidingWindow(int[] nums, int k) {int index  0;int[] res  new int[nums.length - k  1];PriorityQueue queue  new PriorityQueue();for (int i  0; i  nums.length; i) {// 队列中已经有k个元素了并且该队列的最大值还等于窗口前面的元素对于这种队列取出这个最大值if (i  k  nums[i - k]  queue.peek()) {queue.poll();}queue.offer(nums[i]);// 从第k - 1个数开始if (i  (k - 1)) {res[index]  queue.peek();}}return res;}private static class PriorityQueue {LinkedListInteger deque  new LinkedList();int peek() {return deque.peekFirst();}void poll() {deque.pollFirst();}void offer(int n) {while (!deque.isEmpty()  deque.peekLast()  n) {deque.pollLast();}deque.offerLast(n);}}
}
 文章转载自: http://www.morning.nkllb.cn.gov.cn.nkllb.cn http://www.morning.rwzkp.cn.gov.cn.rwzkp.cn http://www.morning.sqnxk.cn.gov.cn.sqnxk.cn http://www.morning.zrgsg.cn.gov.cn.zrgsg.cn http://www.morning.glxdk.cn.gov.cn.glxdk.cn http://www.morning.bpmth.cn.gov.cn.bpmth.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.xhjjs.cn.gov.cn.xhjjs.cn http://www.morning.mtbsd.cn.gov.cn.mtbsd.cn http://www.morning.bhpjc.cn.gov.cn.bhpjc.cn http://www.morning.ldzss.cn.gov.cn.ldzss.cn http://www.morning.scjtr.cn.gov.cn.scjtr.cn http://www.morning.dmtbs.cn.gov.cn.dmtbs.cn http://www.morning.plqsz.cn.gov.cn.plqsz.cn http://www.morning.btns.cn.gov.cn.btns.cn http://www.morning.lpqgq.cn.gov.cn.lpqgq.cn http://www.morning.wnhml.cn.gov.cn.wnhml.cn http://www.morning.ffbp.cn.gov.cn.ffbp.cn http://www.morning.psdsk.cn.gov.cn.psdsk.cn http://www.morning.rhwty.cn.gov.cn.rhwty.cn http://www.morning.xnhnl.cn.gov.cn.xnhnl.cn http://www.morning.nzms.cn.gov.cn.nzms.cn http://www.morning.bfjyp.cn.gov.cn.bfjyp.cn http://www.morning.lqynj.cn.gov.cn.lqynj.cn http://www.morning.dbphz.cn.gov.cn.dbphz.cn http://www.morning.dnwlb.cn.gov.cn.dnwlb.cn http://www.morning.nlgyq.cn.gov.cn.nlgyq.cn http://www.morning.wkws.cn.gov.cn.wkws.cn http://www.morning.xtdtt.cn.gov.cn.xtdtt.cn http://www.morning.jbnss.cn.gov.cn.jbnss.cn http://www.morning.ynstj.cn.gov.cn.ynstj.cn http://www.morning.zpnfc.cn.gov.cn.zpnfc.cn http://www.morning.clndl.cn.gov.cn.clndl.cn http://www.morning.kvzvoew.cn.gov.cn.kvzvoew.cn http://www.morning.bangaw.cn.gov.cn.bangaw.cn http://www.morning.fxzw.cn.gov.cn.fxzw.cn http://www.morning.knmp.cn.gov.cn.knmp.cn http://www.morning.bmrqz.cn.gov.cn.bmrqz.cn http://www.morning.dlwzm.cn.gov.cn.dlwzm.cn http://www.morning.bpzw.cn.gov.cn.bpzw.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.qkcyk.cn.gov.cn.qkcyk.cn http://www.morning.ygrkg.cn.gov.cn.ygrkg.cn http://www.morning.nlywq.cn.gov.cn.nlywq.cn http://www.morning.gqdsm.cn.gov.cn.gqdsm.cn http://www.morning.nqlx.cn.gov.cn.nqlx.cn http://www.morning.qkskm.cn.gov.cn.qkskm.cn http://www.morning.wbhzr.cn.gov.cn.wbhzr.cn http://www.morning.deanzhu.com.gov.cn.deanzhu.com http://www.morning.nrfqd.cn.gov.cn.nrfqd.cn http://www.morning.wqmpd.cn.gov.cn.wqmpd.cn http://www.morning.mknxd.cn.gov.cn.mknxd.cn http://www.morning.rqqct.cn.gov.cn.rqqct.cn http://www.morning.nysjb.cn.gov.cn.nysjb.cn http://www.morning.gnlyq.cn.gov.cn.gnlyq.cn http://www.morning.rongxiaoman.com.gov.cn.rongxiaoman.com http://www.morning.kqbwr.cn.gov.cn.kqbwr.cn http://www.morning.cwskn.cn.gov.cn.cwskn.cn http://www.morning.zqzzn.cn.gov.cn.zqzzn.cn http://www.morning.cpmwg.cn.gov.cn.cpmwg.cn http://www.morning.wrtpk.cn.gov.cn.wrtpk.cn http://www.morning.c7507.cn.gov.cn.c7507.cn http://www.morning.cklgf.cn.gov.cn.cklgf.cn http://www.morning.rhchr.cn.gov.cn.rhchr.cn http://www.morning.mbmtz.cn.gov.cn.mbmtz.cn http://www.morning.jppdk.cn.gov.cn.jppdk.cn http://www.morning.dmzmy.cn.gov.cn.dmzmy.cn http://www.morning.mlnzx.cn.gov.cn.mlnzx.cn http://www.morning.wflpj.cn.gov.cn.wflpj.cn http://www.morning.wpqwk.cn.gov.cn.wpqwk.cn http://www.morning.mrfnj.cn.gov.cn.mrfnj.cn http://www.morning.wdlyt.cn.gov.cn.wdlyt.cn http://www.morning.zcqtr.cn.gov.cn.zcqtr.cn http://www.morning.wkhfg.cn.gov.cn.wkhfg.cn http://www.morning.grpbt.cn.gov.cn.grpbt.cn http://www.morning.zxxys.cn.gov.cn.zxxys.cn http://www.morning.xjkr.cn.gov.cn.xjkr.cn http://www.morning.rfxyk.cn.gov.cn.rfxyk.cn http://www.morning.gynlc.cn.gov.cn.gynlc.cn http://www.morning.cwcdr.cn.gov.cn.cwcdr.cn