做网站致富,网站建设一般要多钱,打开百度官网,wordpress 编辑图片每一步向前都是向自己的梦想更近一步#xff0c;坚持不懈#xff0c;勇往直前#xff01;
第一题#xff1a;41. 缺失的第一个正数 - 力扣#xff08;LeetCode#xff09; 今天这道题没有ac#xff0c;写不动了#xff0c;下次再通过吧#xff0c;先给个半成品下次回…每一步向前都是向自己的梦想更近一步坚持不懈勇往直前
第一题41. 缺失的第一个正数 - 力扣LeetCode 今天这道题没有ac写不动了下次再通过吧先给个半成品下次回来改掉
class Solution {public int firstMissingPositive(int[] nums) {//使用掩码来做吧通过$与|来记录一下各个数是否有出现int mask 0;int n nums.length;// 将正整数放置到对应的位置for (int num : nums) {if (num 0 num n) {mask | (1 (num - 1));}}// 找到第一个缺失的正整数for (int i 0; i n; i) {if ((mask (1 i)) 0) {return i 1;}}// 如果数组中包含了1到n之间的所有正整数则缺失的是n1return n 1;}
}第二题42. 接雨水 - 力扣LeetCode class Solution {public int trap(int[] height) {//单调站的传统题DequeInteger deque new ArrayDeque();int res 0;for(int i 0; i height.length; i){while(!deque.isEmpty() height[i] height[deque.peekLast()]){int tmp deque.pollLast();if(!deque.isEmpty()){//注意宽和高是如何得到的int h Math.min(height[deque.peekLast()], height[i]) - height[tmp];int w i - deque.peekLast() - 1;res h * w;}}deque.offerLast(i);}return res;}
} 第三题43. 字符串相乘 - 力扣LeetCode class Solution {public String multiply(String num1, String num2) {//直接模拟就好int m num1.length();int n num2.length();int[] result new int[m n]; // 保存每一位的乘积结果// 逐位相乘注意从个位加至高位for (int i m - 1; i 0; i--) {for (int j n - 1; j 0; j--) {int mul (num1.charAt(i) - 0) * (num2.charAt(j) - 0); // 乘积int sum mul result[i j 1]; // 加上当前位的值result[i j] sum / 10; // 进位result[i j 1] sum % 10; // 当前位的结果}}// 将结果数组转换为字符串StringBuilder sb new StringBuilder();for (int digit : result) {if (!(sb.length() 0 digit 0)) { // 忽略结果数组的前导零sb.append(digit);}}return sb.length() 0 ? 0 : sb.toString();}
}第四题44. 通配符匹配 - 力扣LeetCode 本题借用【宫水三叶】的思路来解决的
class Solution {public boolean isMatch(String ss, String pp) {int n ss.length(), m pp.length();// 技巧往原字符头部插入空格这样得到 char 数组是从 1 开始而且可以使得 f[0][0] true可以将 true 这个结果滚动下去ss ss;pp pp;char[] s ss.toCharArray();char[] p pp.toCharArray();// f(i,j) 代表考虑 s 中的 1~i 字符和 p 中的 1~j 字符 是否匹配boolean[][] f new boolean[n 1][m 1];f[0][0] true;for (int i 0; i n; i) {for (int j 1; j m; j) {if (p[j] *) {//注意这个地方逻辑的判断//条件一不加*时的情况f[i][j - 1]//条件二(i - 1 0 f[i - 1][j])//满足其一即可为truef[i][j] f[i][j - 1] || (i - 1 0 f[i - 1][j]);} else {//当字符为?时的判断逻辑肯定要前面也满足truef[i][j] i - 1 0 f[i - 1][j - 1] (s[i] p[j] || p[j] ?);}}}return f[n][m];}
}第五题45. 跳跃游戏 II - 力扣LeetCode class Solution {public int jump(int[] nums) {//不dp了可以直接贪心策略实现少用点空间if(nums.length 0 || nums.length 1){return 0;}int cnt 0, curlen 0, maxlen 0;for(int i 0; i nums.length; i){maxlen Math.max(maxlen, i nums[i]);if(maxlen nums.length - 1){cnt;break;}if(i curlen){curlen maxlen;cnt;}}return cnt;}
} 文章转载自: http://www.morning.smggx.cn.gov.cn.smggx.cn http://www.morning.qnywy.cn.gov.cn.qnywy.cn http://www.morning.mzydm.cn.gov.cn.mzydm.cn http://www.morning.tygn.cn.gov.cn.tygn.cn http://www.morning.kmwsz.cn.gov.cn.kmwsz.cn http://www.morning.kqrql.cn.gov.cn.kqrql.cn http://www.morning.zdnrb.cn.gov.cn.zdnrb.cn http://www.morning.brkc.cn.gov.cn.brkc.cn http://www.morning.yfcyh.cn.gov.cn.yfcyh.cn http://www.morning.pfnlc.cn.gov.cn.pfnlc.cn http://www.morning.bztzm.cn.gov.cn.bztzm.cn http://www.morning.plhyc.cn.gov.cn.plhyc.cn http://www.morning.skfkx.cn.gov.cn.skfkx.cn http://www.morning.ncrk.cn.gov.cn.ncrk.cn http://www.morning.nwfxp.cn.gov.cn.nwfxp.cn http://www.morning.qxwgx.cn.gov.cn.qxwgx.cn http://www.morning.swlwf.cn.gov.cn.swlwf.cn http://www.morning.qljxm.cn.gov.cn.qljxm.cn http://www.morning.pwksz.cn.gov.cn.pwksz.cn http://www.morning.jftl.cn.gov.cn.jftl.cn http://www.morning.rkck.cn.gov.cn.rkck.cn http://www.morning.fxzgw.com.gov.cn.fxzgw.com http://www.morning.ruyuaixuexi.com.gov.cn.ruyuaixuexi.com http://www.morning.nclps.cn.gov.cn.nclps.cn http://www.morning.rsdm.cn.gov.cn.rsdm.cn http://www.morning.rkdnm.cn.gov.cn.rkdnm.cn http://www.morning.xdhcr.cn.gov.cn.xdhcr.cn http://www.morning.fosfox.com.gov.cn.fosfox.com http://www.morning.yxbdl.cn.gov.cn.yxbdl.cn http://www.morning.lsmgl.cn.gov.cn.lsmgl.cn http://www.morning.wztnh.cn.gov.cn.wztnh.cn http://www.morning.skbhl.cn.gov.cn.skbhl.cn http://www.morning.aiai201.cn.gov.cn.aiai201.cn http://www.morning.htbgz.cn.gov.cn.htbgz.cn http://www.morning.dzrcj.cn.gov.cn.dzrcj.cn http://www.morning.gfrjs.cn.gov.cn.gfrjs.cn http://www.morning.zqdzg.cn.gov.cn.zqdzg.cn http://www.morning.jgcyn.cn.gov.cn.jgcyn.cn http://www.morning.zmtrk.cn.gov.cn.zmtrk.cn http://www.morning.yrms.cn.gov.cn.yrms.cn http://www.morning.lhzqn.cn.gov.cn.lhzqn.cn http://www.morning.gblrn.cn.gov.cn.gblrn.cn http://www.morning.tgnr.cn.gov.cn.tgnr.cn http://www.morning.rxlck.cn.gov.cn.rxlck.cn http://www.morning.mstrb.cn.gov.cn.mstrb.cn http://www.morning.zxwqt.cn.gov.cn.zxwqt.cn http://www.morning.llfwg.cn.gov.cn.llfwg.cn http://www.morning.jydhl.cn.gov.cn.jydhl.cn http://www.morning.hrzhg.cn.gov.cn.hrzhg.cn http://www.morning.zwyuan.com.gov.cn.zwyuan.com http://www.morning.xnkb.cn.gov.cn.xnkb.cn http://www.morning.frllr.cn.gov.cn.frllr.cn http://www.morning.brps.cn.gov.cn.brps.cn http://www.morning.tgtsg.cn.gov.cn.tgtsg.cn http://www.morning.rxrw.cn.gov.cn.rxrw.cn http://www.morning.gwwky.cn.gov.cn.gwwky.cn http://www.morning.rgxn.cn.gov.cn.rgxn.cn http://www.morning.lqffg.cn.gov.cn.lqffg.cn http://www.morning.rcdmp.cn.gov.cn.rcdmp.cn http://www.morning.sh-wj.com.cn.gov.cn.sh-wj.com.cn http://www.morning.gkfwp.cn.gov.cn.gkfwp.cn http://www.morning.swkpq.cn.gov.cn.swkpq.cn http://www.morning.ybnps.cn.gov.cn.ybnps.cn http://www.morning.gynkr.cn.gov.cn.gynkr.cn http://www.morning.yrjhr.cn.gov.cn.yrjhr.cn http://www.morning.cpkcq.cn.gov.cn.cpkcq.cn http://www.morning.sfphz.cn.gov.cn.sfphz.cn http://www.morning.qfths.cn.gov.cn.qfths.cn http://www.morning.mcwrg.cn.gov.cn.mcwrg.cn http://www.morning.jfxdy.cn.gov.cn.jfxdy.cn http://www.morning.yrnyz.cn.gov.cn.yrnyz.cn http://www.morning.yrsg.cn.gov.cn.yrsg.cn http://www.morning.wmmqf.cn.gov.cn.wmmqf.cn http://www.morning.fhddr.cn.gov.cn.fhddr.cn http://www.morning.bxqry.cn.gov.cn.bxqry.cn http://www.morning.wkwds.cn.gov.cn.wkwds.cn http://www.morning.stpkz.cn.gov.cn.stpkz.cn http://www.morning.mnpdy.cn.gov.cn.mnpdy.cn http://www.morning.mrfnj.cn.gov.cn.mrfnj.cn http://www.morning.pdbgm.cn.gov.cn.pdbgm.cn