Skip to content

Instantly share code, notes, and snippets.

@e2kaneko
Created June 2, 2020 11:58
Show Gist options
  • Save e2kaneko/714fb19d4e6bff4230d9591f1d4afdd3 to your computer and use it in GitHub Desktop.
Save e2kaneko/714fb19d4e6bff4230d9591f1d4afdd3 to your computer and use it in GitHub Desktop.
開発チームの課題(20点)
<?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