Data Structure and Algorithm - Day 01
- 
Master Theorem
![]()
 - 
ArrayList
When insert or delete an element, ArrayList will create a new Array and execute a System.arraycopy. Doing those constantly will reduce efficiency.
 - 
SkipList
space for time | increase dimension
multi-dimension index | log2n-dimension index
![]()
Time complexity: O(log n), Space complexity: O(n)
 - 
283. Move Zeroes
Given an array
nums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.Example:
Input: [0,1,0,3,12] Output: [1,3,12,0,0]Note:
- You must do this in-place without making a copy of the array.
 - Minimize the total number of operations.
 
class Solution { public void moveZeroes(int[] nums) { int i = 0; for (int j = 0; j < nums.length; j++) { if (nums[j] != 0) { swap(nums, i, j); i++; } } } private void swap(int[] nums, int i, int j) { int t = nums[i]; nums[i] = nums[j]; nums[j] = t; } } 
                    
                


                
            
        
浙公网安备 33010602011771号