Leetcode Minimum Spanning Tree Algorithm