In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to replace all question marks with LeetCode. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Title
Give you one that contains only lowercase letters and'?' Character string s, please put all the'?' Convert to several lowercase letters so that the final string does not contain any consecutive repeated characters.
The question test case is guaranteed to be divided by'?' There are no consecutive repeating characters other than characters.
Returns the final string after all conversions are completed (no conversion may be required). If there is more than one solution, return to any one of them. It can be proved that, under given constraints, the answer always exists.
Train of thought
Because I encountered the problem of string replacement in the competition two days ago, I saw this and discussed it with my classmates.
Store the string in an array, traverse it, and determine whether it is'?'
If the current element is the first element and the only element, replace it directly with'a'
If it is not unique, replace it with a different lowercase letter from the latter one
If the current element is the last element, replace it with a different lowercase letter from the previous one
If the current element is in the middle of a string, replace it with lowercase letters that are not the same as before and after
The process of replacement: start with'a'to determine whether the newChar is the same as the characters before / after it, and if so, it will be postponed.
Code public String modifyString (String s) {if (s = = "") {return "the current string is empty, please enter it correctly!" ;} char [] c = s.toCharArray (); for (int I = 0; I
< s.length(); i++) { if(c[i] == '?') { char newChar = 'a'; while ((i>0 & & c [I-1] = = newChar) | | (I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.