Created
December 6, 2013 13:57
-
-
Save sakadonohito/7824204 to your computer and use it in GitHub Desktop.
与えられた文字列が全てユニークかどうか判定する。その4
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 | |
//文字列を配列に変換し、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