leetcode290
2024-09-01 07:31:28
public class Solution {
public bool WordPattern(string pattern, string str) {
var list = str.Split(' ').ToList(); int type1 = ;
int type2 = ; StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder(); Dictionary<string, int> dic1 = new Dictionary<string, int>();
Dictionary<char, int> dic2 = new Dictionary<char, int>(); foreach (var word in list)
{
if (!dic1.ContainsKey(word))
{
dic1.Add(word, type1);
sb1.Append(type1);
type1++;
}
else
{
sb1.Append(dic1[word]);
}
} foreach (var c in pattern)
{
if (!dic2.ContainsKey(c))
{
dic2.Add(c, type2);
sb2.Append(type2);
type2++;
}
else
{
sb2.Append(dic2[c]);
}
} if (sb1.ToString() != sb2.ToString())
{
return false;
}
else
{
return true;
}
}
}
https://leetcode.com/problems/word-pattern/#/description
最新文章
- 原生ajax实现登录(一部分代码)
- 烂泥:nagios学习(四):pnp4nagios图形化绘制nagios数据
- 【poj1144】 Network
- mongoose学习笔记2--增删改查1
- scrollba美化
- CG基础教程-陈惟老师十二讲笔记
- media type与media query
- Composer -- PHP依赖管理的用法
- 【重走Android之路】【Java面向对象基础(三)】面向对象思想
- javascript第三方组件
- 基础连接已经关闭: 未能为SSL/TLS 安全通道建立信任关系
- python+selenium环境配置(windows7环境)
- HBase Client API使用(二)---查询及过滤器
- T4模板试水篇1_入门
- 微渠道发展 BAE交通运输平台和java呼声,微信mysql数据库开发实例 --图文开发教程
- 辅助模式最终考验的是想象力,先来看看怎么用!| Accessibility
- (2)OSi模型
- vue项目打包后的资源路径问题
- 使用perconna xtrabackup备份脚本
- Linux记录- Linux下限制rm -rf /