Skip to content

Instantly share code, notes, and snippets.

@sakadonohito
Created December 6, 2013 13:57
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/7824204 to your computer and use it in GitHub Desktop.
Save sakadonohito/7824204 to your computer and use it in GitHub Desktop.
与えられた文字列が全てユニークかどうか判定する。その4
<?php
//文字列を配列に変換し、1文字ずつスライスしながら重複チェックする
function check_unique($str){
//get length
$len = strlen($str);
//change array
$arr = str_split($str);
for($i=0;$i<$len;$i++){
$char = array_shift($arr);
if(in_array($char,$arr)){
return "False";
}
}
//forを抜けていれば全てユニーク文字という事......のはず。
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