Skip to content

Refactor 03_recursive sum (Java) to use int[] #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

luciannamend
Copy link

"You’re given an array of numbers. You have to add up all the numbers and return the total."

Replaced ArrayList with a primitive int[] in the recursive sum method to improve performance and reduce memory usage.

  • Faster execution: Avoids boxing/unboxing and uses direct array access.
  • Lower memory usage: Primitive arrays are lighter than ArrayList with boxed types.
  • Simpler code: No need for imports or list management for fixed-size data. This version is ideal for static numeric datasets where performance and clarity are priorities.

…and memory efficiency

"You’re given an array of numbers. You have to add up all the numbers and return the total."
 
Replaced ArrayList<Integer> with a primitive int[] in the recursive sum method to improve performance and reduce memory usage.
- Faster execution: Avoids boxing/unboxing and uses direct array access.
- Lower memory usage: Primitive arrays are lighter than ArrayList with boxed types.
- Simpler code: No need for imports or list management for fixed-size data.
This version is ideal for static numeric datasets where performance and clarity are priorities.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant