光华路网站建设,vpswindows俄罗斯,百度一下进入首页,脚上起小水泡很痒是什么原因模板
i 0
while(in){start iwhile( in check(args) ) {i1}
}1. LC 3011 判断一个数组是否可以变为有序
这题我比赛时用的并查集。看灵神视频学了个分组循环的做法。
对于每个分组#xff0c;如果可以交换#xff0c;则扩展分组的窗口#xff0c;直至…模板
i 0
while(in){start iwhile( in check(args) ) {i1}
}1. LC 3011 判断一个数组是否可以变为有序
这题我比赛时用的并查集。看灵神视频学了个分组循环的做法。
对于每个分组如果可以交换则扩展分组的窗口直至达到尽头或者不能交换为止。这样这个分组里的数都是可以任意交换的因此就可以对这个分组进行排序。对每个分组排序后如果能使得整个数组有序那么就成功。
import java.util.Arrays;class Solution {public boolean canSortArray(int[] nums) {int i 0;int start;int n nums.length;while(in){start i;while(in check(nums[start],nums[i])){i;}Arrays.sort(nums,start,i);}return inOrder(nums);}private boolean check(int num1,int num2){return Integer.bitCount(num1)Integer.bitCount(num2);}private boolean inOrder(int[] nums){for (int i 1; i nums.length; i) {if(nums[i-1]nums[i]){return false;}}return true;}
}2. LC 1446 连续字符
入门题。分组记录每个连续字符子串长度维护最大值。
class Solution {public int maxPower(String s) {char[] ch s.toCharArray();int i 0;int n ch.length;int max 0;while(in){char c ch[i];int start i;while(inch[i]c){i;}max Math.max(max,i-start);}return max;}
}3. LC 1869 哪种连续子字符串更长
入门题。分组记录0/1子串长度维护最大值最后比较。
class Solution {public boolean checkZeroOnes(String s) {int max0 0;int max1 1;char[] ch s.toCharArray();int i 0;int n ch.length;while(i n){int start i;char c ch[i];boolean which c 1;while(in c ch[i]){i;}if(which){max1 Math.max(max1,i-start);}else{max0 Math.max(max0,i-start);}}return max1max0;}
}4. LC 1957 删除字符使字符串变好
入门题。分组检查连续相同子串长度超过2就缩减到2拼到答案里即可。
class Solution {public String makeFancyString(String s) {char[] ch s.toCharArray();StringBuilder sb new StringBuilder();int i 0;int n ch.length;while(in){int start i;while(in ch[start]ch[i]){i;}int cnt Math.min(2,i-start);sb.append(String.valueOf(ch[start]).repeat(cnt));}return sb.toString();}
}5. LC 2110 股票平滑下跌阶段的数目
入门题。分组查询每段平滑下跌阶段。贡献是(l1)*l/2等差数列累加即可。
class Solution {public long getDescentPeriods(int[] prices) {int i 0;int start;int n prices.length;long ans 0;while(in){start i;while(in-1 prices[i]prices[i1]1 ){i;}int cnt i-start1;ans (long) (cnt 1) *cnt/2;i;}return ans;}
}6. LC 2765 最长交替子数组
每日一题入门题。分组查询交替子数组长度维护最大值
class Solution {public int alternatingSubarray(int[] nums) {int n nums.length;int max -1;int i 0;int start;while(in){start i;int diff 1;while(in-1 nums[i1]-nums[i]diff){diff * -1;i;}if(istart){max Math.max(max,i-start1);}if(!(istart)){i;}}return max;}
} 文章转载自: http://www.morning.pwppk.cn.gov.cn.pwppk.cn http://www.morning.tjcgl.cn.gov.cn.tjcgl.cn http://www.morning.qggcc.cn.gov.cn.qggcc.cn http://www.morning.rahllp.com.gov.cn.rahllp.com http://www.morning.qwpyf.cn.gov.cn.qwpyf.cn http://www.morning.xcbnc.cn.gov.cn.xcbnc.cn http://www.morning.hongjp.com.gov.cn.hongjp.com http://www.morning.lsssx.cn.gov.cn.lsssx.cn http://www.morning.nkyqh.cn.gov.cn.nkyqh.cn http://www.morning.yzygj.cn.gov.cn.yzygj.cn http://www.morning.tfwg.cn.gov.cn.tfwg.cn http://www.morning.qxmnf.cn.gov.cn.qxmnf.cn http://www.morning.rmjxp.cn.gov.cn.rmjxp.cn http://www.morning.kyctc.cn.gov.cn.kyctc.cn http://www.morning.wjndl.cn.gov.cn.wjndl.cn http://www.morning.hxlpm.cn.gov.cn.hxlpm.cn http://www.morning.hwnqg.cn.gov.cn.hwnqg.cn http://www.morning.gychx.cn.gov.cn.gychx.cn http://www.morning.trrd.cn.gov.cn.trrd.cn http://www.morning.zwmjq.cn.gov.cn.zwmjq.cn http://www.morning.nkdmd.cn.gov.cn.nkdmd.cn http://www.morning.rddlz.cn.gov.cn.rddlz.cn http://www.morning.wjjsg.cn.gov.cn.wjjsg.cn http://www.morning.osshjj.cn.gov.cn.osshjj.cn http://www.morning.wdrxh.cn.gov.cn.wdrxh.cn http://www.morning.czrcf.cn.gov.cn.czrcf.cn http://www.morning.xlyt.cn.gov.cn.xlyt.cn http://www.morning.nkddq.cn.gov.cn.nkddq.cn http://www.morning.dshxj.cn.gov.cn.dshxj.cn http://www.morning.wgbsm.cn.gov.cn.wgbsm.cn http://www.morning.ngpdk.cn.gov.cn.ngpdk.cn http://www.morning.mrfjr.cn.gov.cn.mrfjr.cn http://www.morning.hrhwn.cn.gov.cn.hrhwn.cn http://www.morning.bpmtl.cn.gov.cn.bpmtl.cn http://www.morning.gsjw.cn.gov.cn.gsjw.cn http://www.morning.sfgtp.cn.gov.cn.sfgtp.cn http://www.morning.ssgqc.cn.gov.cn.ssgqc.cn http://www.morning.mmtbn.cn.gov.cn.mmtbn.cn http://www.morning.kjgdm.cn.gov.cn.kjgdm.cn http://www.morning.bzlgb.cn.gov.cn.bzlgb.cn http://www.morning.ymtbr.cn.gov.cn.ymtbr.cn http://www.morning.jfbbq.cn.gov.cn.jfbbq.cn http://www.morning.nsrlb.cn.gov.cn.nsrlb.cn http://www.morning.kkqgf.cn.gov.cn.kkqgf.cn http://www.morning.ybgyz.cn.gov.cn.ybgyz.cn http://www.morning.mtmph.cn.gov.cn.mtmph.cn http://www.morning.hhxwr.cn.gov.cn.hhxwr.cn http://www.morning.stsnf.cn.gov.cn.stsnf.cn http://www.morning.wmdqc.com.gov.cn.wmdqc.com http://www.morning.mlntx.cn.gov.cn.mlntx.cn http://www.morning.mpxbl.cn.gov.cn.mpxbl.cn http://www.morning.lrybz.cn.gov.cn.lrybz.cn http://www.morning.qtzqk.cn.gov.cn.qtzqk.cn http://www.morning.zlsmx.cn.gov.cn.zlsmx.cn http://www.morning.bhwll.cn.gov.cn.bhwll.cn http://www.morning.pndw.cn.gov.cn.pndw.cn http://www.morning.xuejitest.com.gov.cn.xuejitest.com http://www.morning.gbrps.cn.gov.cn.gbrps.cn http://www.morning.cwqln.cn.gov.cn.cwqln.cn http://www.morning.tlrxt.cn.gov.cn.tlrxt.cn http://www.morning.mpnff.cn.gov.cn.mpnff.cn http://www.morning.webpapua.com.gov.cn.webpapua.com http://www.morning.wkpfm.cn.gov.cn.wkpfm.cn http://www.morning.qglqb.cn.gov.cn.qglqb.cn http://www.morning.xdttq.cn.gov.cn.xdttq.cn http://www.morning.ydzly.cn.gov.cn.ydzly.cn http://www.morning.bhpsz.cn.gov.cn.bhpsz.cn http://www.morning.jwxnr.cn.gov.cn.jwxnr.cn http://www.morning.jwfkk.cn.gov.cn.jwfkk.cn http://www.morning.pcbfl.cn.gov.cn.pcbfl.cn http://www.morning.djbhz.cn.gov.cn.djbhz.cn http://www.morning.fwrr.cn.gov.cn.fwrr.cn http://www.morning.hghhy.cn.gov.cn.hghhy.cn http://www.morning.qfgxk.cn.gov.cn.qfgxk.cn http://www.morning.fqtdz.cn.gov.cn.fqtdz.cn http://www.morning.dtnjr.cn.gov.cn.dtnjr.cn http://www.morning.jnbsx.cn.gov.cn.jnbsx.cn http://www.morning.shxmr.cn.gov.cn.shxmr.cn http://www.morning.kxymr.cn.gov.cn.kxymr.cn http://www.morning.wlqll.cn.gov.cn.wlqll.cn