Skip to content

Instantly share code, notes, and snippets.

@KimiyukiYamauchi
Created November 25, 2020 01:53
Show Gist options
  • Save KimiyukiYamauchi/e4261b1ce7b49cf6ba04d9f420ba2ae8 to your computer and use it in GitHub Desktop.
Save KimiyukiYamauchi/e4261b1ce7b49cf6ba04d9f420ba2ae8 to your computer and use it in GitHub Desktop.
/**
*
* @param a - 整数型の配列
* @param idx - 削除の開始の添字
* @param n - 削除する要素数
* @return
* 配列aのidxの位置からn個の要素を削除した配列を
* 返す
* 但し、削除できない場合は元の配列を返す
*/
public int [] ex4_14(int [] a, int idx, int n){
int [] ret;
if (n <= 0 || idx < 0) {
ret = new int[a.length];
for (int i = 0; i < a.length; i++) {
ret[i] = a[i];
}
} else {
if (idx + n >= a.length) {
if (n > a.length - idx ) {
ret = new int[a.length - id]
} else {
ret = new int[a.length];
}
} else {
ret = new int[a.length - n];
}
for (int i = 0, j = 0; i < a.length; i++) {
if ( i < idx || i >= idx + n) {
ret[j++] = a[i];
}
}
}
return ret;
}
@KimiyukiYamauchi
Copy link
Author

これだと通りますね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment