Last active
December 30, 2015 10:58
-
-
Save sakadonohito/7819140 to your computer and use it in GitHub Desktop.
与えられた文字列が全てユニークかどうか判定する。その2
This file contains 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 check_unique($str){ | |
//引数から1文字1要素の配列を生成 | |
$arr = str_split($str); | |
//配列の値をキーにする配列を生成 | |
$tmp = array_combine($arr,$arr); | |
//引数から生成した配列の要素数とその配列から生成した配列の要素数を比較(キーは重複できないので) | |
return count($arr) == count($tmp)?"True":"False"; | |
} | |
//$input = trim(fgets(STDIN)); | |
$input = '1234567890-=\`!@#$%^&*()_+|~qwertyuiop[]QWERTYUIOP{}ASDFGHJKL:"asdfghjkl;\'zxcvbnm,./ZXCVBNM<>?'; | |
$start = microtime(true); | |
echo check_unique($input)."\n"; | |
$end = microtime(true); | |
echo (($end-$start)*1000)."\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
キーに使えない値があると、使えないですね。