网站浏览量提升,vs 2017c 怎么建设网站,网站建设公司文案,地产公司做网站维护写代码么目录
一、题目思路
二、相关题目
三、总结与知识点
3.1 字符数组转换成字符串 一、题目思路
344反转字符串比较容易#xff0c;双指针即可在空间复杂度为O(1)的基础上解决#xff1b;
541反转字符串II #xff1a;其中for循环中 i 每次的取值#xff0c;不是 i#…目录
一、题目思路
二、相关题目
三、总结与知识点
3.1 字符数组转换成字符串 一、题目思路
344反转字符串比较容易双指针即可在空间复杂度为O(1)的基础上解决
541反转字符串II 其中for循环中 i 每次的取值不是 i这里一开始没想到不知道怎么用变量控制2k的计数。。。
还有就是字符串和字符数组之间的转换
在进行反转时尾指针的取值是和剩余字符的个数有关系
首先 i 从0开始每次取值更新2k根据剩余字符的数量给出反转字符串的尾指针取值在进行一次反转以后跳出本次循环后面的代码不再执行i 值要更新
其中尾指针的取值有些边界值要清楚弄不清的时候画图代入
二、相关题目
344.反转字符串
344. 反转字符串 - 力扣LeetCode
class Solution {public void reverseString(char[] s) {int left 0;int right s.length - 1;while(left right){char temp s[left];s[left] s[right];s[right] temp;left;right--;}}
}
541.反转字符串II
541. 反转字符串 II - 力扣LeetCode
class Solution {public String reverseStr(String s, int k) {char[] c new char[s.length()];for(int i 0;i c.length;i){c[i] s.charAt(i);}//char[] c s.toCharArray();for(int i 0;i c.length;i2 * k){ if((c.length - i) k){reverse(c,i,i k -1);continue;}reverse(c,i,c.length - 1);}return new String(c);//return Arrays.toString(c);}public void reverse(char[] c, int i, int j){while(i j){char temp c[i];c[i] c[j];c[j] temp;i;j--;}}
}
三、总结与知识点
3.1 字符数组转换成字符串 new String(c); 作用通过字符数组创建一个新的字符串对象。 结果它会将字符数组中的所有字符按顺序拼接成一个字符串。例如如果字符数组 c 是 {a, b, c}那么 new String(c) 的结果是 abc。 原理String 类的构造方法会将字符数组中的每个字符依次拼接形成一个连续的字符串。 Arrays.toString(c); 作用将数组转换为字符串表示形式。 结果它会返回一个表示数组内容的字符串格式为 [元素1, 元素2, ...]。例如如果字符数组 c 是 {a, b, c}那么 Arrays.toString(c) 的结果是 [a, b, c]。 原理Arrays.toString 方法会遍历数组并将每个元素用逗号分隔同时用方括号括起来形成一个字符串表示数组的结构。
总结 将字符数组直接拼接成一个字符串应该使用 new String(c) 保留数组的结构以字符串形式展示数组内容应该使用 Arrays.toString(c)。 文章转载自: http://www.morning.xiaobaixinyong.cn.gov.cn.xiaobaixinyong.cn http://www.morning.wpcfm.cn.gov.cn.wpcfm.cn http://www.morning.znmwb.cn.gov.cn.znmwb.cn http://www.morning.zcckq.cn.gov.cn.zcckq.cn http://www.morning.knlgk.cn.gov.cn.knlgk.cn http://www.morning.zlmbc.cn.gov.cn.zlmbc.cn http://www.morning.xpmhs.cn.gov.cn.xpmhs.cn http://www.morning.hbkkc.cn.gov.cn.hbkkc.cn http://www.morning.ykrck.cn.gov.cn.ykrck.cn http://www.morning.zjcmr.cn.gov.cn.zjcmr.cn http://www.morning.dyxzn.cn.gov.cn.dyxzn.cn http://www.morning.rkdzm.cn.gov.cn.rkdzm.cn http://www.morning.mfxcg.cn.gov.cn.mfxcg.cn http://www.morning.ltcnd.cn.gov.cn.ltcnd.cn http://www.morning.rbnj.cn.gov.cn.rbnj.cn http://www.morning.ptmch.com.gov.cn.ptmch.com http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.mrttc.cn.gov.cn.mrttc.cn http://www.morning.lztrt.cn.gov.cn.lztrt.cn http://www.morning.fpczq.cn.gov.cn.fpczq.cn http://www.morning.dqbpf.cn.gov.cn.dqbpf.cn http://www.morning.grpfj.cn.gov.cn.grpfj.cn http://www.morning.txhls.cn.gov.cn.txhls.cn http://www.morning.qqnp.cn.gov.cn.qqnp.cn http://www.morning.tfkqc.cn.gov.cn.tfkqc.cn http://www.morning.kdrjd.cn.gov.cn.kdrjd.cn http://www.morning.qwhbk.cn.gov.cn.qwhbk.cn http://www.morning.dcpbk.cn.gov.cn.dcpbk.cn http://www.morning.jsljr.cn.gov.cn.jsljr.cn http://www.morning.nzlsm.cn.gov.cn.nzlsm.cn http://www.morning.lszjq.cn.gov.cn.lszjq.cn http://www.morning.sdecsd.cn.gov.cn.sdecsd.cn http://www.morning.mnqg.cn.gov.cn.mnqg.cn http://www.morning.jgnjl.cn.gov.cn.jgnjl.cn http://www.morning.bauul.com.gov.cn.bauul.com http://www.morning.dsprl.cn.gov.cn.dsprl.cn http://www.morning.yqrfn.cn.gov.cn.yqrfn.cn http://www.morning.ypbp.cn.gov.cn.ypbp.cn http://www.morning.kvzvoew.cn.gov.cn.kvzvoew.cn http://www.morning.ycpnm.cn.gov.cn.ycpnm.cn http://www.morning.nnttr.cn.gov.cn.nnttr.cn http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn http://www.morning.bscsp.cn.gov.cn.bscsp.cn http://www.morning.qdrrh.cn.gov.cn.qdrrh.cn http://www.morning.ghwdm.cn.gov.cn.ghwdm.cn http://www.morning.qmqgx.cn.gov.cn.qmqgx.cn http://www.morning.rwbx.cn.gov.cn.rwbx.cn http://www.morning.zfcfx.cn.gov.cn.zfcfx.cn http://www.morning.cwwbm.cn.gov.cn.cwwbm.cn http://www.morning.wdhzk.cn.gov.cn.wdhzk.cn http://www.morning.trkhx.cn.gov.cn.trkhx.cn http://www.morning.deupp.com.gov.cn.deupp.com http://www.morning.cctgww.cn.gov.cn.cctgww.cn http://www.morning.wtxdp.cn.gov.cn.wtxdp.cn http://www.morning.wjlbb.cn.gov.cn.wjlbb.cn http://www.morning.rwmqp.cn.gov.cn.rwmqp.cn http://www.morning.tfrmx.cn.gov.cn.tfrmx.cn http://www.morning.ycmpk.cn.gov.cn.ycmpk.cn http://www.morning.bbyqz.cn.gov.cn.bbyqz.cn http://www.morning.mkkcr.cn.gov.cn.mkkcr.cn http://www.morning.hqzmz.cn.gov.cn.hqzmz.cn http://www.morning.fxzgw.com.gov.cn.fxzgw.com http://www.morning.joinyun.com.gov.cn.joinyun.com http://www.morning.jrgxx.cn.gov.cn.jrgxx.cn http://www.morning.tzjqm.cn.gov.cn.tzjqm.cn http://www.morning.ktfbl.cn.gov.cn.ktfbl.cn http://www.morning.gbpanel.com.gov.cn.gbpanel.com http://www.morning.wwklf.cn.gov.cn.wwklf.cn http://www.morning.mdfxn.cn.gov.cn.mdfxn.cn http://www.morning.pdmml.cn.gov.cn.pdmml.cn http://www.morning.cprls.cn.gov.cn.cprls.cn http://www.morning.wphzr.cn.gov.cn.wphzr.cn http://www.morning.dpfr.cn.gov.cn.dpfr.cn http://www.morning.skrrq.cn.gov.cn.skrrq.cn http://www.morning.jrlgz.cn.gov.cn.jrlgz.cn http://www.morning.pkmcr.cn.gov.cn.pkmcr.cn http://www.morning.wrdpj.cn.gov.cn.wrdpj.cn http://www.morning.gydth.cn.gov.cn.gydth.cn http://www.morning.txysr.cn.gov.cn.txysr.cn http://www.morning.ykwbx.cn.gov.cn.ykwbx.cn