Java Array Manipulation

前端 未结 3 381
日久生厌
日久生厌 2021-01-27 07:52

I have a function named resize, which takes a source array, and resizes to new widths and height. The method I\'m using, I think, is inefficient. I heard there\'s a better way t

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-27 08:06

    What you have is pretty understandable, and I think it IS an O(n^4) algorithm. Ouchies!

    You can improve it slightly by pushing the i*scale and j*scale out of the inner two loops - they are invariant where they are now. The optimizer might be doing it for you, however. There are also some other similar optimizations.

    Regarding the error, run it twice, once with an input array that's got an even length (6x6) and another that's odd (7x7). And 6x7 and 7x6 while you're at it.

提交回复
热议问题