Created
June 2, 2020 11:58
-
-
Save e2kaneko/714fb19d4e6bff4230d9591f1d4afdd3 to your computer and use it in GitHub Desktop.
開発チームの課題(20点)
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 | |
// 入力 | |
$input = [1, 5, 6, 3, 2, 6]; | |
//$input = [1, 2, 3, 4]; | |
// PHP 配列 初期化 連番でGoogle | |
$seikai = range(1, count($input)); | |
// ①存在するはずだけど存在しない数値を取得 | |
// PHP 配列 差分でGoogle | |
$result1 = array_diff($seikai, $input); | |
// ②2個以上ある数値を取得 | |
// php 配列 要素 回数でGoogle | |
$result2 = array_count_values($input); | |
// ①と②の結果を取得 | |
$result = []; | |
foreach ($result1 as $value) { | |
$result[] = $value; | |
} | |
foreach ($result2 as $key => $value) { | |
if ($value > 1) { | |
$result[] = $key; | |
} | |
} | |
// 結果出力 | |
if (empty($result)) { | |
print 'correct'; | |
} else { | |
print $result[1] . ' ' . $result[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment