From bd234ed89042726876d2460b5aab07ce43fd25a9 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sun, 3 Dec 2023 12:41:47 +0200 Subject: [PATCH] Added tasks 3-10 --- .../php/g0001_0100/s0001_two_sum/Solution.php | 1 - .../Solution.php | 41 +++++++ .../readme.md | 40 +++++++ .../Solution.php | 52 ++++++++ .../readme.md | 50 ++++++++ .../Solution.php | 42 +++++++ .../readme.md | 34 ++++++ .../s0006_zigzag_conversion/Solution.php | 38 ++++++ .../s0006_zigzag_conversion/readme.md | 39 ++++++ .../s0007_reverse_integer/Solution.php | 23 ++++ .../s0007_reverse_integer/readme.md | 35 ++++++ .../s0008_string_to_integer_atoi/Solution.php | 44 +++++++ .../s0008_string_to_integer_atoi/readme.md | 113 ++++++++++++++++++ .../s0009_palindrome_number/Solution.php | 39 ++++++ .../s0009_palindrome_number/readme.md | 41 +++++++ .../Solution.php | 39 ++++++ .../readme.md | 56 +++++++++ .../SolutionTest.php | 19 +++ .../SolutionTest.php | 15 +++ .../SolutionTest.php | 15 +++ .../s0006_zigzag_conversion/SolutionTest.php | 15 +++ .../s0007_reverse_integer/SolutionTest.php | 19 +++ .../SolutionTest.php | 27 +++++ .../s0009_palindrome_number/SolutionTest.php | 19 +++ .../SolutionTest.php | 27 +++++ 25 files changed, 882 insertions(+), 1 deletion(-) create mode 100644 src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.php create mode 100644 src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md create mode 100644 src/main/php/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.php create mode 100644 src/main/php/g0001_0100/s0004_median_of_two_sorted_arrays/readme.md create mode 100644 src/main/php/g0001_0100/s0005_longest_palindromic_substring/Solution.php create mode 100644 src/main/php/g0001_0100/s0005_longest_palindromic_substring/readme.md create mode 100644 src/main/php/g0001_0100/s0006_zigzag_conversion/Solution.php create mode 100644 src/main/php/g0001_0100/s0006_zigzag_conversion/readme.md create mode 100644 src/main/php/g0001_0100/s0007_reverse_integer/Solution.php create mode 100644 src/main/php/g0001_0100/s0007_reverse_integer/readme.md create mode 100644 src/main/php/g0001_0100/s0008_string_to_integer_atoi/Solution.php create mode 100644 src/main/php/g0001_0100/s0008_string_to_integer_atoi/readme.md create mode 100644 src/main/php/g0001_0100/s0009_palindrome_number/Solution.php create mode 100644 src/main/php/g0001_0100/s0009_palindrome_number/readme.md create mode 100644 src/main/php/g0001_0100/s0010_regular_expression_matching/Solution.php create mode 100644 src/main/php/g0001_0100/s0010_regular_expression_matching/readme.md create mode 100644 src/test/php/g0001_0100/s0003_longest_substring_without_repeating_characters/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0004_median_of_two_sorted_arrays/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0005_longest_palindromic_substring/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0006_zigzag_conversion/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0007_reverse_integer/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0008_string_to_integer_atoi/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0009_palindrome_number/SolutionTest.php create mode 100644 src/test/php/g0001_0100/s0010_regular_expression_matching/SolutionTest.php diff --git a/src/main/php/g0001_0100/s0001_two_sum/Solution.php b/src/main/php/g0001_0100/s0001_two_sum/Solution.php index 9fc3f92..dd0c725 100644 --- a/src/main/php/g0001_0100/s0001_two_sum/Solution.php +++ b/src/main/php/g0001_0100/s0001_two_sum/Solution.php @@ -7,7 +7,6 @@ // #2023_11_29_Time_9_ms_(97.47%)_Space_19.8_MB_(77.40%) class Solution { - /** * @param Integer[] $nums * @param Integer $target diff --git a/src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.php b/src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.php new file mode 100644 index 0000000..d10133e --- /dev/null +++ b/src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.php @@ -0,0 +1,41 @@ + $maxLen) { + $maxLen = $curLen; + } + } + + return $maxLen; + } +} diff --git a/src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md b/src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md new file mode 100644 index 0000000..bf1ef46 --- /dev/null +++ b/src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md @@ -0,0 +1,40 @@ +3\. Longest Substring Without Repeating Characters + +Medium + +Given a string `s`, find the length of the **longest substring** without repeating characters. + +**Example 1:** + +**Input:** s = "abcabcbb" + +**Output:** 3 + +**Explanation:** The answer is "abc", with the length of 3. + +**Example 2:** + +**Input:** s = "bbbbb" + +**Output:** 1 + +**Explanation:** The answer is "b", with the length of 1. + +**Example 3:** + +**Input:** s = "pwwkew" + +**Output:** 3 + +**Explanation:** The answer is "wke", with the length of 3. Notice that the answer must be a substring, "pwke" is a subsequence and not a substring. + +**Example 4:** + +**Input:** s = "" + +**Output:** 0 + +**Constraints:** + +* 0 <= s.length <= 5 * 104 +* `s` consists of English letters, digits, symbols and spaces. \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.php b/src/main/php/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.php new file mode 100644 index 0000000..ca60cbc --- /dev/null +++ b/src/main/php/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.php @@ -0,0 +1,52 @@ +-106 <= nums1[i], nums2[i] <= 106 \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0005_longest_palindromic_substring/Solution.php b/src/main/php/g0001_0100/s0005_longest_palindromic_substring/Solution.php new file mode 100644 index 0000000..870b3b9 --- /dev/null +++ b/src/main/php/g0001_0100/s0005_longest_palindromic_substring/Solution.php @@ -0,0 +1,42 @@ +> 1); + if ($start < 0 || $start + $len > $length) { + break; + } + $substr = substr($s, $start, $len); + if ($substr === strrev($substr)) { + $str = $substr; + $max_length = $len; + } elseif ($max_length + 1 < $len) { + break; + } + } + } + + return $str; + } +} diff --git a/src/main/php/g0001_0100/s0005_longest_palindromic_substring/readme.md b/src/main/php/g0001_0100/s0005_longest_palindromic_substring/readme.md new file mode 100644 index 0000000..883ff5c --- /dev/null +++ b/src/main/php/g0001_0100/s0005_longest_palindromic_substring/readme.md @@ -0,0 +1,34 @@ +5\. Longest Palindromic Substring + +Medium + +Given a string `s`, return _the longest palindromic substring_ in `s`. + +**Example 1:** + +**Input:** s = "babad" + +**Output:** "bab" **Note:** "aba" is also a valid answer. + +**Example 2:** + +**Input:** s = "cbbd" + +**Output:** "bb" + +**Example 3:** + +**Input:** s = "a" + +**Output:** "a" + +**Example 4:** + +**Input:** s = "ac" + +**Output:** "a" + +**Constraints:** + +* `1 <= s.length <= 1000` +* `s` consist of only digits and English letters. \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0006_zigzag_conversion/Solution.php b/src/main/php/g0001_0100/s0006_zigzag_conversion/Solution.php new file mode 100644 index 0000000..754f890 --- /dev/null +++ b/src/main/php/g0001_0100/s0006_zigzag_conversion/Solution.php @@ -0,0 +1,38 @@ + 0) { + $row--; + $col++; + } else { + $dir = 'down'; + $row++; + } + } + return implode(array_merge(...$string)); + } +} diff --git a/src/main/php/g0001_0100/s0006_zigzag_conversion/readme.md b/src/main/php/g0001_0100/s0006_zigzag_conversion/readme.md new file mode 100644 index 0000000..4f55d57 --- /dev/null +++ b/src/main/php/g0001_0100/s0006_zigzag_conversion/readme.md @@ -0,0 +1,39 @@ +6\. Zigzag Conversion + +Medium + +The string `"PAYPALISHIRING"` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) + +P A H N A P L S I I G Y I R + +And then read line by line: `"PAHNAPLSIIGYIR"` + +Write the code that will take a string and make this conversion given a number of rows: + +string convert(string s, int numRows); + +**Example 1:** + +**Input:** s = "PAYPALISHIRING", numRows = 3 + +**Output:** "PAHNAPLSIIGYIR" + +**Example 2:** + +**Input:** s = "PAYPALISHIRING", numRows = 4 + +**Output:** "PINALSIGYAHRPI" + +**Explanation:** P I N A L S I G Y A H R P I + +**Example 3:** + +**Input:** s = "A", numRows = 1 + +**Output:** "A" + +**Constraints:** + +* `1 <= s.length <= 1000` +* `s` consists of English letters (lower-case and upper-case), `','` and `'.'`. +* `1 <= numRows <= 1000` \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0007_reverse_integer/Solution.php b/src/main/php/g0001_0100/s0007_reverse_integer/Solution.php new file mode 100644 index 0000000..b98420e --- /dev/null +++ b/src/main/php/g0001_0100/s0007_reverse_integer/Solution.php @@ -0,0 +1,23 @@ + 2147483647 || $li_result < -2147483647) { + $li_result = 0; + } + return $li_result; + } +} diff --git a/src/main/php/g0001_0100/s0007_reverse_integer/readme.md b/src/main/php/g0001_0100/s0007_reverse_integer/readme.md new file mode 100644 index 0000000..81dbb62 --- /dev/null +++ b/src/main/php/g0001_0100/s0007_reverse_integer/readme.md @@ -0,0 +1,35 @@ +7\. Reverse Integer + +Medium + +Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return `0`. + +**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).** + +**Example 1:** + +**Input:** x = 123 + +**Output:** 321 + +**Example 2:** + +**Input:** x = -123 + +**Output:** -321 + +**Example 3:** + +**Input:** x = 120 + +**Output:** 21 + +**Example 4:** + +**Input:** x = 0 + +**Output:** 0 + +**Constraints:** + +* -231 <= x <= 231 - 1 \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0008_string_to_integer_atoi/Solution.php b/src/main/php/g0001_0100/s0008_string_to_integer_atoi/Solution.php new file mode 100644 index 0000000..9804c2b --- /dev/null +++ b/src/main/php/g0001_0100/s0008_string_to_integer_atoi/Solution.php @@ -0,0 +1,44 @@ += 2147483647) { + return 2147483647; + } + if ($res <= -2147483648) { + return -2147483648; + } + } else { + if ($s[$i] == ' ' && $pos == 0) { + continue; + } + if ($s[$i] == '-' && $pos == 0) { + $pos--; + continue; + } + if ($s[$i] == '+' && $pos == 0) { + $pos++; + continue; + } + break; + } + } + return $res; + } +} diff --git a/src/main/php/g0001_0100/s0008_string_to_integer_atoi/readme.md b/src/main/php/g0001_0100/s0008_string_to_integer_atoi/readme.md new file mode 100644 index 0000000..af67f64 --- /dev/null +++ b/src/main/php/g0001_0100/s0008_string_to_integer_atoi/readme.md @@ -0,0 +1,113 @@ +8\. String to Integer (atoi) + +Medium + +Implement the `myAtoi(string s)` function, which converts a string to a 32-bit signed integer (similar to C/C++'s `atoi` function). + +The algorithm for `myAtoi(string s)` is as follows: + +1. Read in and ignore any leading whitespace. +2. Check if the next character (if not already at the end of the string) is `'-'` or `'+'`. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present. +3. Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored. +4. Convert these digits into an integer (i.e. `"123" -> 123`, `"0032" -> 32`). If no digits were read, then the integer is `0`. Change the sign as necessary (from step 2). +5. If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1. +6. Return the integer as the final result. + +**Note:** + +* Only the space character `' '` is considered a whitespace character. +* **Do not ignore** any characters other than the leading whitespace or the rest of the string after the digits. + +**Example 1:** + +**Input:** s = "42" + +**Output:** 42 + +**Explanation:** The underlined characters are what is read in, the caret is the current reader position. + + Step 1: "42" (no characters read because there is no leading whitespace) + ^ + Step 2: "42" (no characters read because there is neither a '-' nor '+') + ^ + Step 3: "42" ("42" is read in) + ^ + +The parsed integer is 42. Since 42 is in the range [-231, 231 - 1], the final result is 42. + +**Example 2:** + +**Input:** s = " -42" + +**Output:** -42 + +**Explanation:** + + Step 1: " -42" (leading whitespace is read and ignored) + ^ + Step 2: " -42" ('-' is read, so the result should be negative) + ^ + Step 3: " -42" ("42" is read in) + ^ + The parsed integer is -42. + +Since -42 is in the range [-231, 231 - 1], the final result is -42. + +**Example 3:** + +**Input:** s = "4193 with words" + +**Output:** 4193 + +**Explanation:** + + Step 1: "4193 with words" (no characters read because there is no leading whitespace) + ^ + Step 2: "4193 with words" (no characters read because there is neither a '-' nor '+') + ^ + Step 3: "4193 with words" ("4193" is read in; reading stops because the next character is a non-digit) + ^ + The parsed integer is 4193. + +Since 4193 is in the range [-231, 231 - 1], the final result is 4193. + +**Example 4:** + +**Input:** s = "words and 987" + +**Output:** 0 + +**Explanation:** + + Step 1: "words and 987" (no characters read because there is no leading whitespace) + ^ + Step 2: "words and 987" (no characters read because there is neither a '-' nor '+') + ^ + Step 3: "words and 987" (reading stops immediately because there is a non-digit 'w') + ^ + The parsed integer is 0 because no digits were read. + +Since 0 is in the range [-231, 231 - 1], the final result is 0. + +**Example 5:** + +**Input:** s = "-91283472332" + +**Output:** -2147483648 + +**Explanation:** + + Step 1: "-91283472332" (no characters read because there is no leading whitespace) + ^ + Step 2: "-91283472332" ('-' is read, so the result should be negative) + ^ + Step 3: "-91283472332" ("91283472332" is read in) + ^ + The parsed integer is -91283472332. + +Since -91283472332 is less than the lower bound of the range [-231, 231 - 1], the final result is clamped to -231 = -2147483648. + +**Constraints:** + +* `0 <= s.length <= 200` +* `s` consists of English letters (lower-case and upper-case), digits (`0-9`), `' '`, `'+'`, `'-'`, and `'.'`. \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0009_palindrome_number/Solution.php b/src/main/php/g0001_0100/s0009_palindrome_number/Solution.php new file mode 100644 index 0000000..bf49357 --- /dev/null +++ b/src/main/php/g0001_0100/s0009_palindrome_number/Solution.php @@ -0,0 +1,39 @@ +-231 <= x <= 231 - 1 + +**Follow up:** Could you solve it without converting the integer to a string? \ No newline at end of file diff --git a/src/main/php/g0001_0100/s0010_regular_expression_matching/Solution.php b/src/main/php/g0001_0100/s0010_regular_expression_matching/Solution.php new file mode 100644 index 0000000..1509038 --- /dev/null +++ b/src/main/php/g0001_0100/s0010_regular_expression_matching/Solution.php @@ -0,0 +1,39 @@ +cache = array_fill(0, strlen($s) + 1, array_fill(0, strlen($p) + 1, null)); + return $this->isMatchHelper($s, $p, 0, 0); + } + + private function isMatchHelper($s, $p, $i, $j) { + if ($j == strlen($p)) { + return $i == strlen($s); + } + if ($this->cache[$i][$j] !== null) { + return $this->cache[$i][$j]; + } + $firstMatch = ($i < strlen($s)) && ($s[$i] == $p[$j] || $p[$j] == '.'); + if (($j + 1) < strlen($p) && $p[$j + 1] == '*') { + $result = ($firstMatch && $this->isMatchHelper($s, $p, $i + 1, $j)) || + $this->isMatchHelper($s, $p, $i, $j + 2); + } else { + $result = $firstMatch && $this->isMatchHelper($s, $p, $i + 1, $j + 1); + } + $this->cache[$i][$j] = $result; + return $result; + } +} diff --git a/src/main/php/g0001_0100/s0010_regular_expression_matching/readme.md b/src/main/php/g0001_0100/s0010_regular_expression_matching/readme.md new file mode 100644 index 0000000..f614e74 --- /dev/null +++ b/src/main/php/g0001_0100/s0010_regular_expression_matching/readme.md @@ -0,0 +1,56 @@ +10\. Regular Expression Matching + +Hard + +Given an input string `s` and a pattern `p`, implement regular expression matching with support for `'.'` and `'*'` where: + +* `'.'` Matches any single character. +* `'*'` Matches zero or more of the preceding element. + +The matching should cover the **entire** input string (not partial). + +**Example 1:** + +**Input:** s = "aa", p = "a" + +**Output:** false + +**Explanation:** "a" does not match the entire string "aa". + +**Example 2:** + +**Input:** s = "aa", p = "a\*" + +**Output:** true + +**Explanation:** '\*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa". + +**Example 3:** + +**Input:** s = "ab", p = ".\*" + +**Output:** true + +**Explanation:** ".\*" means "zero or more (\*) of any character (.)". + +**Example 4:** + +**Input:** s = "aab", p = "c\*a\*b" + +**Output:** true + +**Explanation:** c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches "aab". + +**Example 5:** + +**Input:** s = "mississippi", p = "mis\*is\*p\*." + +**Output:** false + +**Constraints:** + +* `1 <= s.length <= 20` +* `1 <= p.length <= 30` +* `s` contains only lowercase English letters. +* `p` contains only lowercase English letters, `'.'`, and `'*'`. +* It is guaranteed for each appearance of the character `'*'`, there will be a previous valid character to match. \ No newline at end of file diff --git a/src/test/php/g0001_0100/s0003_longest_substring_without_repeating_characters/SolutionTest.php b/src/test/php/g0001_0100/s0003_longest_substring_without_repeating_characters/SolutionTest.php new file mode 100644 index 0000000..26214aa --- /dev/null +++ b/src/test/php/g0001_0100/s0003_longest_substring_without_repeating_characters/SolutionTest.php @@ -0,0 +1,19 @@ +assertEquals(3, (new Solution())->lengthOfLongestSubstring("abcabcbb")); + } + + public function testLengthOfLongestSubstring2() { + $this->assertEquals(1, (new Solution())->lengthOfLongestSubstring("bbbbb")); + } + + public function testLengthOfLongestSubstring3() { + $this->assertEquals(3, (new Solution())->lengthOfLongestSubstring("pwwkew")); + } +} diff --git a/src/test/php/g0001_0100/s0004_median_of_two_sorted_arrays/SolutionTest.php b/src/test/php/g0001_0100/s0004_median_of_two_sorted_arrays/SolutionTest.php new file mode 100644 index 0000000..178a010 --- /dev/null +++ b/src/test/php/g0001_0100/s0004_median_of_two_sorted_arrays/SolutionTest.php @@ -0,0 +1,15 @@ +assertEquals(2.0, (new Solution())->findMedianSortedArrays([1, 3], [2])); + } + + public function testFindMedianSortedArrays2() { + $this->assertEquals(2.5, (new Solution())->findMedianSortedArrays([1, 2], [3, 4])); + } +} diff --git a/src/test/php/g0001_0100/s0005_longest_palindromic_substring/SolutionTest.php b/src/test/php/g0001_0100/s0005_longest_palindromic_substring/SolutionTest.php new file mode 100644 index 0000000..dc0baee --- /dev/null +++ b/src/test/php/g0001_0100/s0005_longest_palindromic_substring/SolutionTest.php @@ -0,0 +1,15 @@ +assertEquals("aba", (new Solution())->longestPalindrome("babad")); + } + + public function testLongestPalindrome2() { + $this->assertEquals("bb", (new Solution())->longestPalindrome("cbbd")); + } +} diff --git a/src/test/php/g0001_0100/s0006_zigzag_conversion/SolutionTest.php b/src/test/php/g0001_0100/s0006_zigzag_conversion/SolutionTest.php new file mode 100644 index 0000000..2a91119 --- /dev/null +++ b/src/test/php/g0001_0100/s0006_zigzag_conversion/SolutionTest.php @@ -0,0 +1,15 @@ +assertEquals("PAHNAPLSIIGYIR", (new Solution())->convert("PAYPALISHIRING", 3)); + } + + public function testConvert2() { + $this->assertEquals("PINALSIGYAHRPI", (new Solution())->convert("PAYPALISHIRING", 4)); + } +} diff --git a/src/test/php/g0001_0100/s0007_reverse_integer/SolutionTest.php b/src/test/php/g0001_0100/s0007_reverse_integer/SolutionTest.php new file mode 100644 index 0000000..21e2cc4 --- /dev/null +++ b/src/test/php/g0001_0100/s0007_reverse_integer/SolutionTest.php @@ -0,0 +1,19 @@ +assertEquals(321, (new Solution())->reverse(123)); + } + + public function testReverse2() { + $this->assertEquals(-321, (new Solution())->reverse(-123)); + } + + public function testReverse3() { + $this->assertEquals(21, (new Solution())->reverse(120)); + } +} diff --git a/src/test/php/g0001_0100/s0008_string_to_integer_atoi/SolutionTest.php b/src/test/php/g0001_0100/s0008_string_to_integer_atoi/SolutionTest.php new file mode 100644 index 0000000..db8873b --- /dev/null +++ b/src/test/php/g0001_0100/s0008_string_to_integer_atoi/SolutionTest.php @@ -0,0 +1,27 @@ +assertEquals(42, (new Solution())->myAtoi("42")); + } + + public function testMyAtoi2() { + $this->assertEquals(-42, (new Solution())->myAtoi(" -42")); + } + + public function testMyAtoi3() { + $this->assertEquals(4193, (new Solution())->myAtoi("4193 with words")); + } + + public function testMyAtoi4() { + $this->assertEquals(0, (new Solution())->myAtoi("words and 987")); + } + + public function testMyAtoi5() { + $this->assertEquals(-2147483648, (new Solution())->myAtoi("-91283472332")); + } +} diff --git a/src/test/php/g0001_0100/s0009_palindrome_number/SolutionTest.php b/src/test/php/g0001_0100/s0009_palindrome_number/SolutionTest.php new file mode 100644 index 0000000..25cfca0 --- /dev/null +++ b/src/test/php/g0001_0100/s0009_palindrome_number/SolutionTest.php @@ -0,0 +1,19 @@ +assertTrue((new Solution())->isPalindrome(121)); + } + + public function testIsPalindrome2() { + $this->assertFalse((new Solution())->isPalindrome(-121)); + } + + public function testIsPalindrome3() { + $this->assertFalse((new Solution())->isPalindrome(10)); + } +} diff --git a/src/test/php/g0001_0100/s0010_regular_expression_matching/SolutionTest.php b/src/test/php/g0001_0100/s0010_regular_expression_matching/SolutionTest.php new file mode 100644 index 0000000..b84a1e2 --- /dev/null +++ b/src/test/php/g0001_0100/s0010_regular_expression_matching/SolutionTest.php @@ -0,0 +1,27 @@ +assertFalse((new Solution())->isMatch("aa", "a")); + } + + public function testIsMatch2() { + $this->assertTrue((new Solution())->isMatch("aa", "a*")); + } + + public function testIsMatch3() { + $this->assertTrue((new Solution())->isMatch("ab", ".*")); + } + + public function testIsMatch4() { + $this->assertTrue((new Solution())->isMatch("aab", "c*a*b")); + } + + public function testIsMatch5() { + $this->assertFalse((new Solution())->isMatch("mississippi", "mis*is*p*.")); + } +}