Skip to content

Instantly share code, notes, and snippets.

@sakadonohito
Created December 6, 2013 13:56
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/7824193 to your computer and use it in GitHub Desktop.
Save sakadonohito/7824193 to your computer and use it in GitHub Desktop.
与えられた文字列が全てユニークかどうか判定する。その3
<?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