Created
December 6, 2013 13:53
-
-
Save sakadonohito/7824159 to your computer and use it in GitHub Desktop.
与えられた文字列が全てユニークかどうか判定する。その1
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){ | |
//引数から配列を生成 | |
$arr = str_split($str); | |
$length = count($arr); | |
//1文字づつ比較 | |
for($i=0;$i<$length;$i++){ | |
$tmp = $arr; | |
$tmp[$i] = ''; | |
if(in_array($arr[$i],$tmp)){ | |
return "False"; | |
} | |
} | |
return "True"; | |
} | |
$input = '1234567890-=\`!@#$%^&*()_+|~qwertyuiop[]QWERTYUIOP{}ASDFGHJKL:"asdfghjkl;\'zxcvbnm,./ZXCVBNM<>?'; | |
//$input = trim(fgets(STDIN)); | |
$start = microtime(true); | |
echo (check_unique($input)?"True":"False")."\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