Skip to content

Instantly share code, notes, and snippets.

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