File tree Expand file tree Collapse file tree 4 files changed +41
-0
lines changed
return-substring-instance-count Expand file tree Collapse file tree 4 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 440440- [ Replace every nth] ( replace-every-nth " 57fcaed83206fb15fd00027a ")
441441- [ Resistor Color Codes] ( resistor-color-codes " 57cf3dad05c186ba22000348 ")
442442- [ Responsible Drinking] ( responsible-drinking " 5aee86c5783bb432cd000018 ")
443+ - [ Return substring instance count] ( return-substring-instance-count " 5168b125faced29f66000005 ")
443444- [ Return the first M multiples of N] ( return-the-first-m-multiples-of-n " 593c9175933500f33400003e ")
444445- [ Reverse a Number] ( reverse-a-number " 555bfd6f9f9f52680f0000c5 ")
445446- [ Reverse the bits in an integer] ( reverse-the-bits-in-an-integer " 5959ec605595565f5c00002b ")
Original file line number Diff line number Diff line change 1+ # [ Return substring instance count] ( https://www.codewars.com/kata/return-substring-instance-count " https://www.codewars.com/kata/5168b125faced29f66000005 ")
2+
3+ Write a function that takes two string parameters ` search_text ` and ` full_text ` and returns the number of times the ` search_text ` is found
4+ within the ` full_text ` .
5+
6+ * Overlap is not permitted: ` "aaa" ` contains ` 1 ` instance of ` "aa" ` , not ` 2 ` .
7+ * ` search_text ` will never be empty.
8+
9+ ## Examples:
10+
11+ ```
12+ full_text = "aa_bb_cc_dd_bb_e", search_text = "bb"
13+ -- > should return 2 since "bb" shows up twice
14+
15+ full_text = "aaabbbcccc", search_text = "bbb"
16+ -- > should return 1
17+ ```
Original file line number Diff line number Diff line change 1+ interface Solution {
2+ static int substringCount (String fullText , String search ) {
3+ return (fullText + "_" ).split (search ).length - 1 ;
4+ }
5+ }
Original file line number Diff line number Diff line change 1+ import static org .junit .jupiter .api .Assertions .assertEquals ;
2+
3+ import org .junit .jupiter .params .ParameterizedTest ;
4+ import org .junit .jupiter .params .provider .CsvSource ;
5+
6+ class SolutionTest {
7+ @ ParameterizedTest
8+ @ CsvSource (delimiter = '|' , textBlock = """
9+ abcdeb | b | 2
10+ abcdeb | a | 1
11+ ccddeeccddeecc | cc | 3
12+ aaabbbccc | bb | 1
13+ ,,,..239,,,,,., | ,, | 3
14+ """ )
15+ void sample (String fullText , String search , int expected ) {
16+ assertEquals (expected , Solution .substringCount (fullText , search ));
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments