楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

领英VO 挂经

🔗
matthewyih 2022-1-17 10:07:00 | 只看该作者
全局:
力扣比赛能前500的表示其叁零还真不是一般难..
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-WZV42  2022-1-17 23:04:35
matthewyih 发表于 2022-1-16 18:07
力扣比赛能前500的表示其叁零还真不是一般难..

一般我面别人 看到利口上太难的 都会简化一下拿去面别人
这个题竟然还人为增加难度。。。
回复

使用道具 举报

🔗
ThinkDeeper2 2022-2-25 15:28:06 | 只看该作者
全局:
本帖最后由 ThinkDeeper2 于 2022-2-24 23:35 编辑

感觉DFS  backtracking 很 straightforward, 大概意思:
  1.         Dictionary<string, HashSet<string>> map = new Dictionary<string, HashSet<string>>();
  2.         public static void Main(string[] args)
  3.         {
  4.                 string s = "abac";
  5.                 HashSet<String> res = new HashSet<string>();
  6.                 res = Dfs(s, 0, s.Length-1);               
  7.         }

  8.         public HashSet<string> Dfs(String s, int start, int end)
  9.         {
  10.                 if(start > end)
  11.                         return new HashSet<string>();
  12.                        
  13.                 if(start==end)
  14.                 {
  15.                         return new HashSet<string>()
  16.                         {
  17.                                 s.Substring(start,1)
  18.                         }
  19.                 }
  20.                
  21.                 string sub =s.Substring(start, end-start+1);
  22.                 if(map.ContainsKey(s.Substring(start, end-start+1))
  23.                 {
  24.                         return map[sub];
  25.                 }
  26.                
  27.                 HashSet<string> center = Dfs(s, start+1, end-1);
  28.                 HashSet<String> res = new HashSet<string>(center);
  29.                 if (s[start] == s[end])
  30.                 {
  31.                         foreach (string i in center)
  32.                         {
  33.                                 res.Add(s[start] + i + s[end]);
  34.                         }
  35.                         res.Add(s[start].ToString());
  36.                         res.Add(s[start].ToString() + s[end]);
  37.                 }
  38.                 else
  39.                 {
  40.                         HashSet<string> left = Dfs(s, start, end - 2);
  41.                         HashSet<string> right = Dfs(s, start + 1, end - 1);

  42.                         res.AddAll(left);
  43.                         res.AddAll(right);
  44.                 }
  45.                 return res;
  46.         }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表