This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| https://leetcode.com/problems/two-sum/submissions/ | |
| Given an array of integers, return indices of the two numbers such that they add up to a specific target. | |
| You may assume that each input would have exactly one solution, and you may not use the same element twice. | |
| Example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const arr = [ | |
| "apple", | |
| [ | |
| "banana", | |
| "strawberry", | |
| "apple", | |
| ["banana", "strawberry", "apple", ["banana", "strawberry", "apple"]] | |
| ] | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function arrayFlat(array $array): array | |
| { | |
| return array_reduce($array, function ($acc, $item) { | |
| return array_merge($acc, is_array($item) ? arrayFlat($item) : [$item]); | |
| }, []); | |
| } | |
| function countItems(array $arr, string $item): int | |
| { |
NewerOlder