php 10的次方,动态 - 1的10次方 - OSCHINA - 中文开源技术交流社区
你們都說得對,可是下面這個代碼怎么優化呢?
public String(int[] codePoints, int offset, int count) {
if (offset < 0) {
throw new StringIndexOutOfBoundsException(offset);
}
if (count < 0) {
throw new StringIndexOutOfBoundsException(count);
}
// Note: offset or count might be near -1>>>1.
if (offset > codePoints.length - count) {
throw new StringIndexOutOfBoundsException(offset + count);
}
final int end = offset + count;
// Pass 1: Compute precise size of char[]
int n = count;
for (int i = offset; i < end; i++) {
int c = codePoints[i];
if (Character.isBmpCodePoint(c))
continue;
else if (Character.isValidCodePoint(c))
n++;
else throw new IllegalArgumentException(Integer.toString(c));
}
// Pass 2: Allocate and fill in char[]
final char[] v = new char[n];
for (int i = offset, j = 0; i < end; i++, j++) {
int c = codePoints[i];
if (Character.isBmpCodePoint(c))
v[j] = (char)c;
else
Character.toSurrogates(c, v, j++);
}
this.value = v;
}
總結
以上是生活随笔為你收集整理的php 10的次方,动态 - 1的10次方 - OSCHINA - 中文开源技术交流社区的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (并查集)The Suspects
- 下一篇: 动态规划算法php,php算法学习之动态