Created
November 25, 2020 01:53
-
-
Save KimiyukiYamauchi/e4261b1ce7b49cf6ba04d9f420ba2ae8 to your computer and use it in GitHub Desktop.
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
/** | |
* | |
* @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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
これだと通りますね