随笔分类 -  union find

947. Most Stones Removed with Same Row or Column
摘要:On a 2D plane, we place stones at some integer coordinate points. Each coordinate point may have at most one stone. Now, a move consists of removing a 阅读全文

posted @ 2019-01-21 00:31 猪猪🐷

685. Redundant Connection II
摘要:In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, exce... 阅读全文

posted @ 2018-11-09 07:34 猪猪🐷

737. Sentence Similarity II
摘要:737. Sentence Similarity II Given two sentences words1, words2 (each represented as an array of strings), and a list of similar word pairs pairs, determine if two sentences are similar. For example... 阅读全文

posted @ 2018-09-20 18:26 猪猪🐷

399. Evaluate Division
摘要:399. Evaluate Division Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return th... 阅读全文

posted @ 2018-08-28 21:19 猪猪🐷

684. Redundant Connection
摘要:In this problem, a tree is an undirected graph that is connected and has no cycles. The given input is a graph that started as a tree with N nodes (wi 阅读全文

posted @ 2018-08-28 20:08 猪猪🐷

721. Accounts Merge
摘要:Given a list accounts, each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements a 阅读全文

posted @ 2018-08-09 18:59 猪猪🐷

200. Number of Islands
摘要:Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacen 阅读全文

posted @ 2018-08-09 18:10 猪猪🐷

305. Number of Islands II
摘要:A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand operation which turns the water at position (row, col) 阅读全文

posted @ 2018-08-09 18:09 猪猪🐷

uf basics
摘要:uf // quick find: // use int array id[] of length n // p and q are connected if and only if they have the same id // when merge components containing p and q, change all entris who // id equals id... 阅读全文

posted @ 2018-08-09 18:08 猪猪🐷

导航