C언어 알고리즘 최적화 과제
안녕하세요. 과제로 보기에 있는 코드들을 comment한 러닝타임에 맞게 최적화를 시켜야 하는데 저기서 어떻게 더 최적화를 시켜야할지 잘 모르겠네요.
// O(nlogn)
bool distinct(int a[], int len) {
assert(a);
assert(len > 0);
for (int i = 0; i < len; ++i) {
for (int j = i + 1; j < len; ++j) {
if (a[i] == a[j]) {
return false;
}
}
}
return true;
}
// O(n)
bool distinct_range(const int a[], int len) {
assert(a);
assert(len > 0);
for (int i = 0; i < len; ++i) {
for (int j = i + 1; j < len; ++j) {
if (a[i] == a[j]) {
return false;
}
}
}
return true;
}