Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. Example:...


Please answer the question in the screenshot. The language used here is Java. Please give the source code.


Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such<br>that there is a bijection between a letter in pattern and a non-empty word in str. Example:<br>1. pattern =
map = new HashMap(); map.put('a', "apple"); // add a pair map.get('a'); // return apple map. containsKey('a'); // return true map.containsvalue(“banana") // false Note: Your method should start with the required name and parameters: class PatternChecker { public boolean check(String pattern, string str) { // ... } "/>
Extracted text: Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. Example: 1. pattern = "abba", str = "dog cat cat dog" should return true. 2. pattern = "abba", str = "dog cat cat fish" should return false. 3. pattern = "aaaa", str = "dog cat cat dog" should return false. 4. pattern = "abba", str = "dog dog dog dog" should return false. Notes: You may assume pattern contains only lowercase letters, and str contains lowercase letters separated by a single space. The code is partially finished, and you have to use the provided parameter name. Pseudocode is not accepted. Hint: You may find the usage of HashMap helpful for solving this problem. Map map = new HashMap(); map.put('a', "apple"); // add a pair map.get('a'); // return apple map. containsKey('a'); // return true map.containsvalue(“banana") // false Note: Your method should start with the required name and parameters: class PatternChecker { public boolean check(String pattern, string str) { // ... }
Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here