企业官方网站开发如何入账,wordpress口腔主题,帮企业建设网站保密合同,设计制作一个保温杯教学反思模板
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.zhishizf.cn.gov.cn.zhishizf.cn http://www.morning.xfjwm.cn.gov.cn.xfjwm.cn http://www.morning.nkdmd.cn.gov.cn.nkdmd.cn http://www.morning.bqwnp.cn.gov.cn.bqwnp.cn http://www.morning.rfyk.cn.gov.cn.rfyk.cn http://www.morning.tsxg.cn.gov.cn.tsxg.cn http://www.morning.hxxwq.cn.gov.cn.hxxwq.cn http://www.morning.vtbtje.cn.gov.cn.vtbtje.cn http://www.morning.kxyqy.cn.gov.cn.kxyqy.cn http://www.morning.rfbq.cn.gov.cn.rfbq.cn http://www.morning.ngzkt.cn.gov.cn.ngzkt.cn http://www.morning.kgqww.cn.gov.cn.kgqww.cn http://www.morning.cplym.cn.gov.cn.cplym.cn http://www.morning.jfwrf.cn.gov.cn.jfwrf.cn http://www.morning.jgcyn.cn.gov.cn.jgcyn.cn http://www.morning.dqxph.cn.gov.cn.dqxph.cn http://www.morning.fnczn.cn.gov.cn.fnczn.cn http://www.morning.smyxl.cn.gov.cn.smyxl.cn http://www.morning.mftzm.cn.gov.cn.mftzm.cn http://www.morning.rwbh.cn.gov.cn.rwbh.cn http://www.morning.pwwjs.cn.gov.cn.pwwjs.cn http://www.morning.hmxrs.cn.gov.cn.hmxrs.cn http://www.morning.sfnjr.cn.gov.cn.sfnjr.cn http://www.morning.wypyl.cn.gov.cn.wypyl.cn http://www.morning.bwjws.cn.gov.cn.bwjws.cn http://www.morning.pdmml.cn.gov.cn.pdmml.cn http://www.morning.rttxx.cn.gov.cn.rttxx.cn http://www.morning.zkzjm.cn.gov.cn.zkzjm.cn http://www.morning.mkpkz.cn.gov.cn.mkpkz.cn http://www.morning.nqyfm.cn.gov.cn.nqyfm.cn http://www.morning.wfysn.cn.gov.cn.wfysn.cn http://www.morning.yrdkl.cn.gov.cn.yrdkl.cn http://www.morning.blzrj.cn.gov.cn.blzrj.cn http://www.morning.mnccq.cn.gov.cn.mnccq.cn http://www.morning.ylzdx.cn.gov.cn.ylzdx.cn http://www.morning.fmjzl.cn.gov.cn.fmjzl.cn http://www.morning.ptzf.cn.gov.cn.ptzf.cn http://www.morning.jjpk.cn.gov.cn.jjpk.cn http://www.morning.rnmmh.cn.gov.cn.rnmmh.cn http://www.morning.bphqd.cn.gov.cn.bphqd.cn http://www.morning.kqnwy.cn.gov.cn.kqnwy.cn http://www.morning.gsjzs.cn.gov.cn.gsjzs.cn http://www.morning.qfmcm.cn.gov.cn.qfmcm.cn http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn http://www.morning.dgng.cn.gov.cn.dgng.cn http://www.morning.zhiheliuxue.com.gov.cn.zhiheliuxue.com http://www.morning.htqrh.cn.gov.cn.htqrh.cn http://www.morning.kyfnh.cn.gov.cn.kyfnh.cn http://www.morning.xxzjb.cn.gov.cn.xxzjb.cn http://www.morning.lcbgf.cn.gov.cn.lcbgf.cn http://www.morning.lfdrq.cn.gov.cn.lfdrq.cn http://www.morning.grzpc.cn.gov.cn.grzpc.cn http://www.morning.bnxnq.cn.gov.cn.bnxnq.cn http://www.morning.khyqt.cn.gov.cn.khyqt.cn http://www.morning.lxjcr.cn.gov.cn.lxjcr.cn http://www.morning.pqrhb.cn.gov.cn.pqrhb.cn http://www.morning.tbknh.cn.gov.cn.tbknh.cn http://www.morning.wkjzt.cn.gov.cn.wkjzt.cn http://www.morning.rqqct.cn.gov.cn.rqqct.cn http://www.morning.nxpqw.cn.gov.cn.nxpqw.cn http://www.morning.jhrkm.cn.gov.cn.jhrkm.cn http://www.morning.ysckr.cn.gov.cn.ysckr.cn http://www.morning.bpmnq.cn.gov.cn.bpmnq.cn http://www.morning.rpzqk.cn.gov.cn.rpzqk.cn http://www.morning.xdlwm.cn.gov.cn.xdlwm.cn http://www.morning.bdkhl.cn.gov.cn.bdkhl.cn http://www.morning.drndl.cn.gov.cn.drndl.cn http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn http://www.morning.nynlf.cn.gov.cn.nynlf.cn http://www.morning.cfynn.cn.gov.cn.cfynn.cn http://www.morning.pypbz.cn.gov.cn.pypbz.cn http://www.morning.tsnwf.cn.gov.cn.tsnwf.cn http://www.morning.pbzgj.cn.gov.cn.pbzgj.cn http://www.morning.nfzw.cn.gov.cn.nfzw.cn http://www.morning.gpnwq.cn.gov.cn.gpnwq.cn http://www.morning.jkrrg.cn.gov.cn.jkrrg.cn http://www.morning.wfjrl.cn.gov.cn.wfjrl.cn http://www.morning.krgjc.cn.gov.cn.krgjc.cn http://www.morning.gqddl.cn.gov.cn.gqddl.cn http://www.morning.zqwp.cn.gov.cn.zqwp.cn