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

最新文章

  1. 原生ajax实现登录(一部分代码)
  2. 烂泥:nagios学习(四):pnp4nagios图形化绘制nagios数据
  3. 【poj1144】 Network
  4. mongoose学习笔记2--增删改查1
  5. scrollba美化
  6. CG基础教程-陈惟老师十二讲笔记
  7. media type与media query
  8. Composer -- PHP依赖管理的用法
  9. 【重走Android之路】【Java面向对象基础(三)】面向对象思想
  10. javascript第三方组件
  11. 基础连接已经关闭: 未能为SSL/TLS 安全通道建立信任关系
  12. python+selenium环境配置(windows7环境)
  13. HBase Client API使用(二)---查询及过滤器
  14. T4模板试水篇1_入门
  15. 微渠道发展 BAE交通运输平台和java呼声,微信mysql数据库开发实例 --图文开发教程
  16. 辅助模式最终考验的是想象力,先来看看怎么用!| Accessibility
  17. (2)OSi模型
  18. vue项目打包后的资源路径问题
  19. 使用perconna xtrabackup备份脚本
  20. Linux记录- Linux下限制rm -rf /

热门文章

  1. bzoj1854: [Scoi2010]游戏 贪心
  2. uva10689矩阵快速幂
  3. word问题禁止宏
  4. Python3 条件控制(九)
  5. 【LeetCode 222_完全二叉树_遍历】Count Complete Tree Nodes
  6. 集成学习之Boosting —— Gradient Boosting原理
  7. mysql数据添加时如果这条数据存在进行修改
  8. 网站微信登录-python 实现
  9. c++下为使用pimpl方法的类编写高效的swap函数
  10. Http协议——Header说明