Last active
December 17, 2019 13:58
-
-
Save carousel/adc1f12fe3233596959e04c2b0681a71 to your computer and use it in GitHub Desktop.
Caclulate new size for dynamic array in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Integer newSize(Integer currentSize, Integer inputSize) { | |
if (currentSize > inputSize) { | |
return currentSize * 2; | |
} else if (currentSize < inputSize) { | |
return (inputSize % currentSize == 0) ? (currentSize + inputSize) : (currentSize + inputSize + 1); | |
} else { | |
return currentSize + inputSize; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment