g2601_2700.s2677_chunk_array.solution.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
The newest version!
// #Easy #2023_09_11_Time_49_ms_(96.15%)_Space_44.4_MB_(96.63%)
function chunk(arr: any[], size: number): any[][] {
if (arr.length === 0) return []
if (size >= arr.length) return [arr]
let i: number = 0
let res: Array> = []
while (i < arr.length) {
res.push(arr.slice(i, i + size))
i += size
}
return res
}
export { chunk }
© 2015 - 2024 Weber Informatics LLC | Privacy Policy