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>的更多相关文章

  1. 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 ...

  2. 地区sql

    /*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...

  3. 11 - 改变vtkImageData中的Manipulation 方法 VTK 6.0 迁移

    VTK6 引入了许多不兼容的变.这其中就包括关于vtkImageData中元数据管理及内存分配的方法.这些方法有些直接改变了行为或者能加了额外的参数. GetScalarTypeMin() GetSc ...

  4. Data manipulation primitives in R and Python

    Data manipulation primitives in R and Python Both R and Python are incredibly good tools to manipula ...

  5. 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 ...

  6. 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 ...

  7. jquery-1.11.1.js

       每次想要使用这个js时,总是要到官网上下载,太麻烦,现在把它收录了 jquery-1.11.1.js /*! * jQuery JavaScript Library v1.11.1 * http ...

  8. 通过c++11的condition_variable实现的有最大缓存限制的队列

    之前曾写过一个通过C++11的condition_variable实现的有最大缓存限制的队列,底层使用std::queue来实现,如果想要提升性能的话,可以考虑改用固定的长度环形数组.环形数组实现如下 ...

  9. [转帖]Introduction to text manipulation on UNIX-based systems

    Introduction to text manipulation on UNIX-based systems https://www.ibm.com/developerworks/aix/libra ...

随机推荐

  1. Mac流程图的软件

    里面有破解机器,按照步骤一步步来就可以了 https://www.zhinin.com/omnigraffle_pro-mac.html

  2. 能耗监测平台GPRS通讯服务器的架构设计

    在这个文章里面我将用一个实际的案例来分享如何来构建一个能够接受3000+个连接的GPRS通讯服务器软件.在这里,我将分享GPRS通讯服务器设计过程中面临的问题,分享通讯协议的设计,分享基于异步事件的设 ...

  3. Wireshark使用入门

    目录 1. Wireshark介绍 1.1 客户端界面 1.2 Display Filter 的常用方法 1.3 界面上一些小TIPS 2. 使用Wireshark分析TCP三次握手过程 2.1 三次 ...

  4. FFmpeg 常用API

    一.通用API 1.1 av_register_all() 初始化 libavformat 和注册所有的复用器.解复用器和协议处理器.如果不调用这个函数,可以调用下面的三个函数来选择支持的格式. 注册 ...

  5. 【shell脚本】创建账户及删除账户,批量创建账户及批量删除账户===autoCreateUser.sh

    一.字符串运算符 二.创建账户 1.提示用户输入用户名和密码,脚本自动创建相应的账户及配置密码.如果用户不输入账户名,则提示必须输入账户名并退出脚本;如果用户不输入密码,则统一使用默认的 123456 ...

  6. HashMap的底层原理(jdk1.7.0_79)

    前言 在Java中我们最常用的集合类毫无疑问就是Map,其中HashMap作为Map最重要的实现类在我们代码中出现的评率也是很高的. 我们对HashMap最常用的操作就是put和get了,那么你知道它 ...

  7. 【Easyexcel】java导入导出超大数据量的xlsx文件 解决方法

    解决方法: 使用easyexcel解决超大数据量的导入导出xlsx文件 easyexcel最大支持行数 1048576. 官网地址: https://alibaba-easyexcel.github. ...

  8. 【RT-Thread笔记】IO设备模型及GPIO设备

    RTT内核对象--设备 RT-Thread有多种内核对象,其中设备device就是其中一种. 内核继承关系图如下: 设备继承关系图如下: device对象对应的结构体如下: 其中,设备类型type有如 ...

  9. Locust 接口性能测试 - 转载一 (后期熟悉实践自己出一套完整的)

    转载大佬   ,.. 另外一篇:https://www.cnblogs.com/imyalost/p/9758189.html记录一下接口性能测试的学习 先熟悉一下概念: Locust是使用Pytho ...

  10. dos转unix

    方式一 # yum install dos2unix.x86_64 # dos2unix file 方式二 查看样式: :set ff? //dos/unix 设置: :set fileformat= ...