Insist on doing small things, then witness the magic
12345678910111213141516
class Solution { public int triangularSum(int[] nums) { Deque<Integer> numQ = new ArrayDeque<>(); for (int num : nums) { numQ.offer(num); } while (numQ.size() > 1) { for (int i = numQ.size() - 1; i > 0; i--) { int topNum = numQ.poll(); numQ.offer((topNum + numQ.peekFirst()) % 10); } numQ.poll(); } return numQ.poll(); }}
直接用queue.
时间复杂度: O(n!)空间复杂度: O(n)
Calm Patient Persistent