| Conditions | 7 |
| Paths | 16 |
| Total Lines | 24 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | public static function isAnagram2(string $s, string $t): bool |
||
| 29 | { |
||
| 30 | [$m, $n] = [strlen($s), strlen($t)]; |
||
| 31 | if ($m !== $n) { |
||
| 32 | return false; |
||
| 33 | } |
||
| 34 | $map = array_fill(0, 26, 0); |
||
| 35 | for ($i = 0; $i < $m; $i++) { |
||
| 36 | $key = ord($s[$i]) - ord('a'); |
||
| 37 | if (isset($map[$key])) { |
||
| 38 | $map[$key]++; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | for ($i = 0; $i < $n; $i++) { |
||
| 42 | $key = ord($t[$i]) - ord('a'); |
||
| 43 | if (isset($map[$key])) { |
||
| 44 | $map[$key]--; |
||
| 45 | } |
||
| 46 | if ($map[$key] < 0) { |
||
| 47 | return false; |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | return true; |
||
| 52 | } |
||
| 54 |