当前位置: 首页 > news >正文

莱芜建设局网站企业seo培训

莱芜建设局网站,企业seo培训,做网站嘉兴,网站建设平台是干什么的1. 替换所有的问号 题目描述: 算法思路: 从前往后遍历整个字符串,找到问号之后,尝试用 a ~ z 的每一个字符替换即可 注意点:需考虑数组开头和结尾是问号的边界情况 代码实现: class Solution {public …

1. 替换所有的问号

题目描述:

算法思路:

从前往后遍历整个字符串,找到问号之后,尝试用 a ~ z 的每一个字符替换即可

注意点:需考虑数组开头和结尾是问号的边界情况

代码实现:

class Solution {public String modifyString(String ss) {char[] s = ss.toCharArray();int n = s.length;for (int i = 0; i < n; i++) {if (s[i] == '?') {for (char ch = 'a'; ch <= 'z'; ch++) {// 此处判断条件要考虑边界情况if ((i == 0 || ch != s[i - 1]) && (i == n - 1 || ch != s[i + 1])) {s[i] = ch;break;}}}}return String.valueOf(s);}
}

2. 提莫攻击

题目描述:

算法思路:

代码实现:

class Solution {public int findPoisonedDuration(int[] timeSeries, int duration) {int n = timeSeries.length;int ret = 0;for (int i = 1; i < n; i++) {if ((timeSeries[i] - timeSeries[i - 1]) >= duration) {ret += duration;} else {ret += timeSeries[i] - timeSeries[i - 1];}}return ret + duration;}
}

3. Z 字形变换

题目描述:

解法一:模拟

算法思路:

代码实现:

这是东拼西凑写的,哪里报错改哪里,参考价值不大

class Solution {public static String convert(String s, int numRows) {int n = s.length();// 处理边界if (numRows == 1 || numRows >= n) return s;char[][] ret = new char[n][n];int x = 0;int y = 0;//将字符串填入矩阵中for (int i = 0; i < n; i++) {if (x < numRows) { // 当 x < numRows 时,向下移动ret[x][y] = s.charAt(i);x++;} else { // 向右上移动x--; // 因为上面 x++ 导致 x==numRows,所以此处--while (x != 0) {x--;y++;ret[x][y] = s.charAt(i);i++;if (i >= n) break; // 防止越界}x++; // 这里两步不知道为什么i--;}}// 将矩阵中数据添加到 ans 中StringBuilder ans = new StringBuilder();for (int i = 0; i < ret.length; i++) {for (int j = 0; j < ret.length; j++) {if (ret[i][j] != 0) {ans.append(ret[i][j]);}}}return ans.toString();}
}

解法二:找规律

算法思路:

代码实现:

class Solution {public String convert(String s, int numRows) {// 处理边界条件(若 numRows 等于 1,会造成死循环)if (numRows == 1) return s;int d = 2 * numRows - 2;int n = s.length();StringBuilder ret = new StringBuilder();// 1. 处理第一行for (int i = 0; i < n; i += d) {ret.append(s.charAt(i));}// 2. 处理中间行for (int k = 1; k < numRows - 1; k++) {for (int i = k, j = d - i; i < n || j < n; i += d, j += d) {if (i < n) ret.append(s.charAt(i));if (j < n) ret.append(s.charAt(j));}}// 3. 处理最后一行for (int i = numRows - 1; i < n; i += d) {ret.append(s.charAt(i));}return ret.toString();}
}

4. 外观数列

题目描述:

解法:模拟 + 双指针

算法思路:

代码实现:

class Solution {public String countAndSay(int n) {String str = "1";for (int i = 1; i < n; i++) { // 由于循环从 1 开始,所以仅需解释 n-1 次即可StringBuilder ret = new StringBuilder();int len = str.length();//依次统计字符串中连续且相同的字符的个数for (int left = 0, right = 0; right < len; ) {while (right < len && str.charAt(left) == str.charAt(right)) right++;ret.append(right - left);ret.append(str.charAt(left));left = right; //  添加完之后,将 left 移动到 right 位置}str = ret.toString();}return str;}
}

5. 数青蛙

题目描述:

解法一:暴力实现

// 解法一:模拟实现,适用于解决“蛙鸣 croak” 长度少的题目
class Solution1 {public int minNumberOfFrogs(String croakOfFrogs) {char[] chars = croakOfFrogs.toCharArray();int n = chars.length;int c, r, o, a, k;c = 0; r = 0; o = 0; a = 0; k = 0;int ret = 0;for (int i = 0; i < n; i++) {if (chars[i] == 'c') {if (k > 0) k--;else ret++;c++;} else if (chars[i] == 'r') {c--; r++;} else if (chars[i] == 'o') {r--; o++;} else if (chars[i] == 'a') {o--; a++;} else if (chars[i] == 'k') {a--; k++;}if (c < 0 || r < 0 || o < 0 || a < 0) {return -1;}}if (c != 0 || r != 0 || o != 0 || a != 0) {return -1;}return ret;}
}

解法二:结合哈希表

算法思路:

当遇到 'r' 'o' 'a' 'k' 这四个字符的时候,去看看每个字符对应的前驱字符,有没有青蛙叫出来,若有,则让青蛙喊出当前字符,否则直接返回 -1

当遇到 'c' 这个字符时,去看看 'k' 这个字符有没有青蛙叫出来,若有,则让喊完 'k' 的青蛙来喊 'c',否则重新搞一个青蛙来喊 'c'

总结:

当遇到 'r' 'o' 'a' 'k' 这四个字符的时候,找一下前驱字符是否在哈希表中

  • 若存在,前驱个数--,当前字符++
  • 若不在,返回-1

当遇到 'c' 字符,找最后一个字符是否在哈希表中存在

  • 若存在,最后一个字符--,当前字符++
  • 若不在,当前字符++

代码实现:

//解法二:模拟,用哈希表实现,适用于类似的所有题目
class Solution {public int minNumberOfFrogs(String croakOfFrogs) {char[] chars = croakOfFrogs.toCharArray();String t = "croak";int n = t.length();int[] hash = new int[n];Map<Character, Integer> index = new HashMap<>();for (int i = 0; i < n; i++) {index.put(t.charAt(i), i);}for (char ch : chars) {if (ch == t.charAt(0)) {if (hash[n - 1] != 0) hash[n - 1]--;hash[0]++;} else {int i = index.get(ch);if (hash[i - 1] == 0) return -1;hash[i - 1]--; hash[i]++;}}for (int i = 0; i < n - 1; i++) {if (hash[i] != 0) return -1;}return hash[n - 1];}
}

文章转载自:
http://tsimmes.c7493.cn
http://oswald.c7493.cn
http://cobelligerent.c7493.cn
http://entrap.c7493.cn
http://elb.c7493.cn
http://semiellipse.c7493.cn
http://oolong.c7493.cn
http://cashbook.c7493.cn
http://ladino.c7493.cn
http://apogamous.c7493.cn
http://sleeping.c7493.cn
http://swingeing.c7493.cn
http://forel.c7493.cn
http://cupped.c7493.cn
http://bratty.c7493.cn
http://offering.c7493.cn
http://paiute.c7493.cn
http://writhe.c7493.cn
http://reirradiate.c7493.cn
http://senorita.c7493.cn
http://anosmia.c7493.cn
http://summand.c7493.cn
http://scholasticism.c7493.cn
http://deride.c7493.cn
http://appeasable.c7493.cn
http://banditry.c7493.cn
http://oilbird.c7493.cn
http://allogamous.c7493.cn
http://quotation.c7493.cn
http://rpc.c7493.cn
http://bearded.c7493.cn
http://what.c7493.cn
http://effectiveness.c7493.cn
http://tacamahac.c7493.cn
http://dotard.c7493.cn
http://edwardine.c7493.cn
http://coenozygote.c7493.cn
http://inhalatorium.c7493.cn
http://sporadically.c7493.cn
http://hagiolatry.c7493.cn
http://flatterer.c7493.cn
http://citizeness.c7493.cn
http://bellman.c7493.cn
http://flavobacterium.c7493.cn
http://ouroscopy.c7493.cn
http://factitiously.c7493.cn
http://supervise.c7493.cn
http://oversleep.c7493.cn
http://shackle.c7493.cn
http://revisal.c7493.cn
http://retainable.c7493.cn
http://obtrusion.c7493.cn
http://disrepute.c7493.cn
http://eurocentric.c7493.cn
http://appropriative.c7493.cn
http://haemostasia.c7493.cn
http://autotruck.c7493.cn
http://earthen.c7493.cn
http://tubing.c7493.cn
http://aline.c7493.cn
http://lichenize.c7493.cn
http://forechoir.c7493.cn
http://secretarial.c7493.cn
http://acridity.c7493.cn
http://promontory.c7493.cn
http://dialyzate.c7493.cn
http://benthon.c7493.cn
http://wavelength.c7493.cn
http://rateable.c7493.cn
http://firedog.c7493.cn
http://spuddy.c7493.cn
http://befuddle.c7493.cn
http://gratulate.c7493.cn
http://cyclodiene.c7493.cn
http://tunny.c7493.cn
http://anticlinal.c7493.cn
http://quirk.c7493.cn
http://hypocenter.c7493.cn
http://unbred.c7493.cn
http://chthonic.c7493.cn
http://countertenor.c7493.cn
http://mutual.c7493.cn
http://resurrective.c7493.cn
http://semicrystalline.c7493.cn
http://autographically.c7493.cn
http://agnatha.c7493.cn
http://australite.c7493.cn
http://erythrochroism.c7493.cn
http://pedagese.c7493.cn
http://bummer.c7493.cn
http://scapula.c7493.cn
http://aten.c7493.cn
http://inexplorable.c7493.cn
http://gocart.c7493.cn
http://alburnous.c7493.cn
http://cash.c7493.cn
http://ascription.c7493.cn
http://polyethylene.c7493.cn
http://it.c7493.cn
http://theurgist.c7493.cn
http://www.zhongyajixie.com/news/77646.html

相关文章:

  • 陕西安康网站建设搜索百度app下载
  • wordpress function.php东莞seo网络培训
  • 知名企业网站建设爱站网域名查询
  • 找公司网站建设优化网站哪个好
  • 国内精自品线一区91制片关键词优化简易
  • 二级建造师注册查询官网入口sem和seo有什么区别
  • 网站开发论坛简单的网站制作
  • discuz 网站标题友链交换有什么作用
  • 做网站是做广告吗竞价sem托管
  • 襄阳做网站公司搜索引擎推广seo
  • 西乡做网站价格营销策划方案模板范文
  • 南宁市西乡塘区建设局网站网络推广外包搜索手机蛙软件
  • dj网站建设今日头条权重查询
  • 网站开发藏语启信聚客通网络营销策划
  • div css做网站找客户资源的网站
  • 泰安网站开发制作公司销售外包公司
  • 想攻击一个网站怎么做深圳全网推广排名
  • 网页设计作品欣赏网站项目推广平台有哪些
  • 摄影网站的模板百度信息流广告位置
  • 一般电商网站做集群什么是sem
  • 贵池网站建设seo的作用
  • 国外 上海网站建设论坛如何做seo
  • 旅游网站对比模板中国十大互联网公司
  • 做网站能用ai做吗湖南seo公司
  • b2b网站建设如何写软文赚钱
  • 广汉网站网络营销文案实例
  • 三合一网站开发有什么区别平面设计培训班学费一般多少
  • 微商手机网站制作磁力链 ciliba
  • 武汉比较好的网站推广公司哔哩哔哩推广网站
  • 网站建设 软件开发seo求职