Created
December 6, 2013 13:56
-
-
Save sakadonohito/7824193 to your computer and use it in GitHub Desktop.
与えられた文字列が全てユニークかどうか判定する。その3
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){ | |
$len = strlen($str); | |
for($i=0;$i<$len;$i++){ | |
$char = substr($str,$i,1); | |
//検査対象の文字が文字列のどの位置にあるかを前からと後ろから走査して文字位置が違うとFalse(uniqueではない) | |
if(strpos($str,$char) != strrpos($str,$char)){ | |
return "False"; | |
} | |
} | |
return "True"; | |
} | |
//$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