| Conditions | 5 |
| Paths | 7 |
| Total Lines | 17 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function firstUniqChar(string $s): int |
||
| 10 | { |
||
| 11 | if (empty($s)) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | $n = strlen($s); |
||
| 15 | $map = array_fill(0, 26, 0); |
||
| 16 | for ($i = 0; $i < $n; $i++) { |
||
| 17 | $map[ord($s[$i]) - 26] = ($map[ord($s[$i]) - 26] ?? 0) + 1; |
||
| 18 | } |
||
| 19 | for ($i = 0; $i < $n; $i++) { |
||
| 20 | if ($map[ord($s[$i]) - 26] === 1) { |
||
| 21 | return $i; |
||
| 22 | } |
||
| 23 | } |
||
| 24 | |||
| 25 | return -1; |
||
| 26 | } |
||
| 28 |