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 ...
随机推荐
- k8s 二进制部署详解
环境说明: 192.168.1.101 -- master01 + etcd01 192.168.1.102 -- etcd02 192.168.1.103 -- etcd03 192.168.1.1 ...
- linux中dd命令详解
本文转自:https://www.cnblogs.com/yuanqiangfei/p/9138625.html 一.dd命令的解释 dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换. ...
- 配置每次git push 不需要输入账号密码
配置每次git push 不需要输入账号密码 .gitconfig文件地址 C:\Users\Admin
- 在Visual Studio 中使用 <AutoGenerateBindingRedirects> 来解决引用的程序集版本冲突问题
问题: https://stackoverflow.com/questions/42836248/using-autogeneratebindingredirects-in-visual-studio ...
- Rust从入门到放弃(1)—— hello,world
安装及环境配置 特点:安全,性能,并发 rust源配置 RLS安装 cargo rust管理工具,该工具可以愉快方便的管理rust工程 #!/bin/bash mkdir learn cd learn ...
- Kubernetes RBAC授权普通用户对命名空间访问权限
Kubernetes RBAC授权普通用户对命名空间访问权限 官方文档:https://www.cnblogs.com/xiangsikai/p/11413970.html kind: Role ap ...
- virsh console配置
If you're trying to get to the console, you can either use virt-viewer for the graphical console or ...
- 用Python完成毫秒级抢单,助你秒杀淘宝大单
目录: 引言 环境 需求分析&前期准备 淘宝购物流程回顾 秒杀的实现 代码梳理 总结 0 引言 年中购物618大狂欢开始了,各大电商又开始了大力度的折扣促销,我们的小胖又给大家谋了一波福利,淘 ...
- FastDFS图片服务器(分布式文件系统)学习。
参考:https://blog.csdn.net/hiqingtian/article/details/79413471 https://blog.csdn.net/sinat_40399893/ar ...
- E203 译码模块(1)
E203是两级流水线结构,第一级是IFU进行取指操作,第二级包括译码.执行.交付和写回等功能.架构图如下: https://www.cnblogs.com/images/cnblogs_com/mik ...