MulaiMulai sekarang secara gratis

Space complexity in find max value

In the code you just implemented in the previous exercise, what was the space complexity of the findMaxValue method?

public int findMaxValue(int[] data) {
  // Initialize the maximum value to the first element
  int max = data[0];

  for (int value : data) {
    // Update max if current element is greater
    if (value > max) {
      max = value;
    }
  }

  return max;
}

Latihan ini adalah bagian dari kursus

Optimizing Code in Java

Lihat Kursus

Latihan interaktif praktis

Ubah teori menjadi tindakan dengan salah satu latihan interaktif kami.

Mulai berolahraga