In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.