Replace wild cards with all possible combinations of zeros and ones using recursion.
Input String: 0?1?
Output: 0010, 0011, 0110, 0111
Solution:
public List<String> replaceQuestionMark(String s) { List<String> result = new LinkedList<String>(); replaceQuestionMarkRecursive(result, s.toCharArray(), 0); //System.out.println(Arrays.toString(result.toArray())); return result; } private void replaceQuestionMarkRecursive(List<String> result, char[] chars, int start) { if(start == chars.length) { result.add(new String(chars)); return; } if(chars[start] == '?') { chars[start] = '0'; replaceQuestionMarkRecursive(result, chars, start+1); chars[start] = '1'; replaceQuestionMarkRecursive(result, chars, start+1); chars[start] = '?'; } else { replaceQuestionMarkRecursive(result, chars, start+1); } }
相关推荐
Combinations of IntelligentMethods and Application
Electronic structrues and transport properties of zigzag BNC nanoribbons with different combinations of BN and graphene nanoribbons
Then you will build your first IoT application with Blynk using various hardware combinations and connectivity types such as Ethernet and Wi-Fi. Then you'll use and configure various widgets (control...
namely an expression that captures, in a compact way, the analysis result with respect to all possible combinations of scenarios, and allows for their exploration at interactive speed. We will ...
reader with the mathematical background needed to design many optical combinations that are used in astronomical telescopes and cameras.1 The results presented here were obtained by using a different ...
After an overview of preliminary concepts, this text introduces stacks and queues using arrays along with a discussion of array-based lists. This is followed by an introduction to linked lists and the...
大师Donald E. Knuth(汉名高德纳)的著作,计算机程序设计与艺术第四卷3册:生成所有组合和分划Generating All Combinations and Permutations(中英)
differences (JNDs) for the average observer and scene, transformations for different combinations of observer sensitivity and scene susceptibility were derived. The psychophysical results were used to...
goal of formulating and using more realistic mathematical models of the tyre in a wide range of operational conditions has been achieved. From the point of view of the vehicle dynamicist, the ...
The topics include Cycle and Intersection Detection in Linked Lists, Finding the First Node of a Cycle, Generation of Permutations and Combinations with and without Repetition, Reconstruction of ...
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephon
This book is devoted to new methods of control for complex dynamical systems and deals with nonlinear control systems having several degrees of freedom, subjected to unknown disturbances, and ...
Errors associated with the prediction performance of the networks were estimated using statistical methods and were found to be within satisfactory range of accuracy. Finally, this study shows that ...
* Lots of modules with color variations, endless combinations with icons and badges possible * 2-1-3 column ordering for search engine friendliness * Compact size, using gzip and image sprites * Works...
proper combinations of threshold level and enhanced vaccination rate based on threshold policy can lead disease prevalence to a previously chosen level if eradication of disease is impossible.
Learn smart solutions that will help you avoid pitfalls while building apps that can scale up to a multitude of possible Android device-and-browser combinations. Teaches practical techniques for ...
Figure 8.24 shows the 36 possible combinations of the two dice. Your app should roll the dice 36,000 times. Use a one-dimensional array to tally the number of times each possible sum appears. Display...
so many permutations and combinations possible, it is easy to go astray. This paper is the result of Cisco’s experience with many different customers and it represents a common sense approach to ...
You will work with build variants, such as debug and release, paid and free, and even combinations of these things. The book will also help you set up unit and integration testing with different ...
* Lots of modules with color variations, endless combinations with icons and badges possible * 2-1-3 column ordering for search engine friendliness * Compact size, using gzip and image sprites * Works...