leetcode389: Find the Difference,
来源:互联网 发布:淘宝违禁词查询神器 编辑:程序博客网 时间:2024/05/03 17:32
要求:给出两个字符串s,t s是随机生成的由小写字母组成的字符串,t在s的基础上增加了一个字母,希望找出这个增加的字母。
注意:想用异或运算来找不同。因为两个字符串只有一处不同,所以先把它们放入同一个数组中,那么每个元素都会重复一次,增加的字母除外。再用异或来寻找那个没有重复字母。
public static char findTheDifference(String s, String t) {char[] sa=s.toCharArray();char[] ta=t.toCharArray();char[] c=new char[sa.length+ta.length];for(int j=0;j<sa.length;++j)c[j]=sa[j];for(int j=0;j<ta.length;++j)c[sa.length+j]=ta[j];char result=c[0];for(int j=1;j<c.length;++j)result^=c[j];return result;}
0 0
- LeetCode389. Find the Difference
- leetcode389: Find the Difference,
- Leetcode389. Find the Difference
- leetcode389. Find the Difference
- leetcode389. Find the Difference
- LeetCode389. Find the Difference简单
- leetcode389 Find the Difference java
- python--leetcode389. Find the Difference
- leetcode389[easy]---Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- Find the Difference
- 160.Find the Difference
- Find the Difference
- 389. Find the Difference
- Leetcode:Find the Difference
- SQL笔记第一部分(select基础)
- leetCode_Palindrome Pairs
- 栈的弹出序列是否与压入序列匹配?
- 微信小程序开发之选项卡(窗口底部TabBar)页面切换
- 20161023
- leetcode389: Find the Difference,
- 织梦调用当前栏目名称,链接
- 第十五天学习笔记
- 字节流 字符流
- 跨域与同源策略
- Android TextView中文字通过SpannableString来设置超链接、颜色、字体等属性
- java中Token验证
- android JNI 开发
- HTML-列表