11/6 <bit manipulation>
389. Find the Difference
^ (按位异或): 参加运算的两个数,如果两个相应位为“异”(值不同),则该位结果为1,否则为0。
抵消掉相同的位,剩下的就是多余的位。
class Solution {
public char findTheDifference(String s, String t) {
char c = t.charAt(t.length() - 1);
for(int i = 0; i < s.length(); i++){
c ^= s.charAt(i);
c ^= t.charAt(i);
}
return c;
}
}
318. Maximum Product of Word Lengths
value[i] |= 1 << (tmp.charAt(j) - 'a');
int大小为32位,全部只有26个小写字母,每一位表示一个字母。
&(按位与) :对应位均为1时,结果位为1,否则为0
| (按位或):参加运算的两个数只要两个数中的一个为1,结果就为1
class Solution {
public int maxProduct(String[] words) {
if(words == null || words.length == 0)
return 0;
int len = words.length;
int[] value = new int[len];
for(int i = 0; i < len; i++){
String tmp = words[i];
value[i] = 0;
for(int j = 0; j < tmp.length(); j++){
value[i] |= 1 << (tmp.charAt(j) - 'a');
}
}
int maxProduct = 0;
for(int i = 0; i < len; i++)
for(int j = i + 1; j < len; j++){
if((value[i] & value[j]) == 0 && (words[i].length() * words[j].length() > maxProduct))
maxProduct = words[i].length() * words[j].length();
}
return maxProduct;
}
}
11/6 <bit manipulation>的更多相关文章
- MySQL Crash Course #04# Chapter 7. 8 AND. OR. IN. NOT. LIKE
索引 AND. OR 运算顺序 IN Operator VS. OR NOT 在 MySQL 中的表现 LIKE 之注意事项 运用通配符的技巧 Understanding Order of Evalu ...
- 地区sql
/*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...
- 11 - 改变vtkImageData中的Manipulation 方法 VTK 6.0 迁移
VTK6 引入了许多不兼容的变.这其中就包括关于vtkImageData中元数据管理及内存分配的方法.这些方法有些直接改变了行为或者能加了额外的参数. GetScalarTypeMin() GetSc ...
- Data manipulation primitives in R and Python
Data manipulation primitives in R and Python Both R and Python are incredibly good tools to manipula ...
- Best packages for data manipulation in R
dplyr and data.table are amazing packages that make data manipulation in R fun. Both packages have t ...
- java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
1.错误描写叙述 java.sql.SQLException: Can not issue data manipulation statements with executeQuery(). at c ...
- jquery-1.11.1.js
每次想要使用这个js时,总是要到官网上下载,太麻烦,现在把它收录了 jquery-1.11.1.js /*! * jQuery JavaScript Library v1.11.1 * http ...
- 通过c++11的condition_variable实现的有最大缓存限制的队列
之前曾写过一个通过C++11的condition_variable实现的有最大缓存限制的队列,底层使用std::queue来实现,如果想要提升性能的话,可以考虑改用固定的长度环形数组.环形数组实现如下 ...
- [转帖]Introduction to text manipulation on UNIX-based systems
Introduction to text manipulation on UNIX-based systems https://www.ibm.com/developerworks/aix/libra ...
随机推荐
- 有关tab页的
有关tab页的 1.静态的 2.动态的可以删除的 3.删除右侧,左侧,全部,除了自己以外的. 4.多了可以自动伸缩. 5.带shown事件.可以反向影响菜单去.
- 一文读懂前端技术演进:盘点Web前端20年的技术变迁史
本文原文由作者“司徒正美”发布于公众号“前端你别闹”,即时通讯网收录时有改动,感谢原作者的分享. 1.引言 1990 年,第一个Web浏览器的诞生:1991 年,WWW诞生,这标志着前端技术的开始. ...
- TP5 使用验证码功能
工作中后台开发使用的是 TP5,但是对语法不是很熟悉,总是看着手册写代码.当时做 Java 的时候也是这样,很多语法需要靠百度.不是不能写代码,但是这样的效率感觉不高,没有行云流水的感觉,要是能有聊天 ...
- Go gRPC Hello World
概述 开始 gRPC 了,这篇文章学习使用 gRPC,输出一个 Hello World. 用 Go 实现 gRPC 的服务端. 用 Go 实现 gRPC 的客户端. gRPC 支持 4 类服务方法,咱 ...
- openssl编译安装
最新版本可以在这个网站下载: https://www.openssl.org/source/ wget https://www.openssl.org/source/openssl-1.1.1c.ta ...
- WinForm 窗体间传递数据
前言 做项目的时候,winfrom因为没有B/S的缓存机制,窗体间传递数据没有B/S页面传递数据那么方便,今天我们就说下winfrom中窗体传值的几种方式. 共有字段传递 共有字段传递实现起来很方便, ...
- cuda,cudnn
20191008 服务器上的cuda总是被人搞坏掉,好烦.记录下: 卸载干净cuda sudo rm -rf /usr/local/cuda sudo apt-get remove cuda sudo ...
- NET Excel转换为集合对象
1.仅适用于规则Excel:表头和数据一一对应 2.涉及到Excel转换为集合对象的部分代码,完整npoi帮助类点击查看 /// <summary> /// 默认把excel第一个shee ...
- C#编辑xml文件
string path = @"C:\Users\Administrator\Desktop\无人智能便利店\install\收银端\XMLRFI.xml"; XmlDocumen ...
- 350道面试题分享,拿下京东offer工资double
350道面试题分享,拿下京东offer工资double 前言: 面试,其实是一个双向选择的过程,在这个过程里,我们不应该抱着畏惧的心态去对待,这样反而会影响自己的发挥.同时看中的应该不止薪资,还要看你 ...