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 ...
随机推荐
- vs安装包离线下载
1.首先打开visual studio 的官网下载最新的安装程序. https://www.visualstudio.com/zh-hans/?rr=https%3A%2F%2Fwww.baidu.c ...
- ThreadLocal 简单解析
ThreadLocal 简单解析 基于jdk1.8 ThreadLocal一定不陌生,开发中常用,也是面试里的常客了,但是往往我们可能只是知道该类的作用.学习该类对于个人的多线程编码能力是大有裨益的, ...
- what is variable?
what is variable? variable:pytorch中的变量,存储tensor,数值会不断变动 在 Torch 中的 Variable 就是一个存放会变化的值的地理位置. 里面的值会不 ...
- Python连载23-file_analysis
一.文件 1.定义:长久保存信息的一种信息集合 2.常用操作:(1)打开关闭(2)读写内容(3)查找 3.open函数 (1)意义:打开文件,带有很多参数 (2)第一个参数:必须有,文件的路径和名称 ...
- Vue.js 源码分析(一) 代码结构
关于Vue vue是一个兴起的前端js库,是一个精简的MVVM.MVVM模式是由经典的软件架构MVC衍生来的,当View(视图层)变化时,会自动更新到ViewModel(视图模型),反之亦然,View ...
- UVA 291 The House Of Santa Claus DFS
题目: In your childhood you most likely had to solve the riddle of the house of Santa Claus. Do you re ...
- sql server 下载安装标记
SQL Server 2017 的各版本和支持的功能 https://docs.microsoft.com/zh-cn/sql/sql-server/editions-and-components-o ...
- 【MySQL】MMM和MHA高可用架构
用途 对MySQL主从复制集群的Master的健康监控. 当Master宕机后把写VIP迁移到新Master. 重新配置集群中的其他Slave从新Master同步 MMM架构 主服务器发生故障时, 1 ...
- RHCE实验记录总结-1-RHCSA
不管是运维还是开发系统的了解下Linux或者系统的温习整理一下Linux知识点无疑是较好的,这篇文章是对RHCSA&RHCE实验进行一个汇总,是我为了做实验方便(并分享给朋友)的一篇文章. 前 ...
- Serverless 的喧哗与骚动(一)附Serverless行业发展回顾
作者 | 阿里中间件高级技术专家 许晓斌 <Maven实战>作者,曾负责 AliExpress 微服务架构演进,现在负责阿里集团 Serverless 技术研发落地. 导读:从 2016 ...