LeetCode 2879: Display the First Three Rows

Problem Description

Explanation:

To display the first three rows of the DataFrame, we can simply iterate over the DataFrame and print the first three rows.

  • Algorithm:

    1. Initialize a variable to keep track of the current row count.
    2. Iterate over the DataFrame and print each row until the row count reaches 3.
  • Time Complexity: O(n) where n is the number of rows in the DataFrame.

  • Space Complexity: O(1)

:

Solutions

import java.util.List;

public class DisplayFirstThreeRows {
    public void displayFirstThreeRows(List<List<Object>> dataFrame) {
        int rowCount = 0;
        for (List<Object> row : dataFrame) {
            if (rowCount >= 3) {
                break;
            }
            System.out.println(row);
            rowCount++;
        }
    }
}

Loading editor...