决定把门口两棵松树砍了# Living
e*s
1 楼
最近做题和看板上的帖子,个人觉得hash这个东西用来删除或避免重复是不是不靠谱。
因为有conflict。
比如一道leetcode的题
Generate Parentheses
//Given n pairs of parentheses, write a function to generate all
combinations of well-formed parentheses.
//For example, given n = 3, a solution set is:
//"((()))", "(()())", "(())()", "()(())", "()()()"
我想用DP,每次在前一个结果基础上 左边加"()",右边加"(),再把整个"(" + result
+ ")".
用HashSet来存放结果,每次加的时候自动排除重复。
我想问HashSet是不是不能保证100%正确? 正确的做法应该是怎么样了?
因为有conflict。
比如一道leetcode的题
Generate Parentheses
//Given n pairs of parentheses, write a function to generate all
combinations of well-formed parentheses.
//For example, given n = 3, a solution set is:
//"((()))", "(()())", "(())()", "()(())", "()()()"
我想用DP,每次在前一个结果基础上 左边加"()",右边加"(),再把整个"(" + result
+ ")".
用HashSet来存放结果,每次加的时候自动排除重复。
我想问HashSet是不是不能保证100%正确? 正确的做法应该是怎么样了?