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 Intelligent Methods and Application #### 栈意与重点 该书的标题表明其主要内容是探讨不同智能方法的结合以及这些结合在实际中的应用。智能方法可以包括人工智能的各种子领域和技术,...
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 ...
- **3.1.1 With a Truth Table:** Using truth tables to determine the output for all possible input combinations. - **3.1.2 With a Boolean Function:** Representing the circuit's behavior using a Boolean...
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(中英)
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 topic covers algorithms for generating all possible combinations of bits within a word. These algorithms are fundamental in combinatorial problems and testing scenarios. #### 1.25 Generating Bit...
- **Generating Bit Combinations**: Algorithms for generating all possible combinations of bits. - **Generating Bit Subsets of a Given Word**: Techniques for generating subsets of a given bit pattern...
* 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.
- **Generating Bit Combinations**: Algorithms for generating all possible combinations of bits. - **Generating Bit Subsets of a Given Word**: Generating subsets of a given binary word. - **Binary ...
of offenses and victims with those of offenders. Information was extracted from police files concerning 345 burglars and 310 violent offenders in Nottinghamshire, England. The most important ...
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...