Skip to content

Instantly share code, notes, and snippets.

@sakadonohito
Last active December 30, 2015 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakadonohito/7819140 to your computer and use it in GitHub Desktop.
Save sakadonohito/7819140 to your computer and use it in GitHub Desktop.
与えられた文字列が全てユニークかどうか判定する。その2
<?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";
?>
@sakadonohito
Copy link
Author

キーに使えない値があると、使えないですね。

@sakadonohito
Copy link
Author

いや、使える?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment