问题描述:

方法:

class Solution(object):
def getSum(self, a, b):
"""
:type a: int
:type b: int
:rtype: int
"""
lis = [a,b]
return sum(lis)

另:

 class Solution(object):
def getSum(self, a, b):
"""
:type a: int
:type b: int
:rtype: int
"""
no_carry_sum=a^b
carry_sum=(a&b)<<1 左移一位 3<<1 6 3 & 1 = 1进位
return sum([no_carry_sum,carry_sum])

2018-09-27 09:42:03

LeetCode--371--两整数之和的更多相关文章

  1. Java实现 LeetCode 371 两整数之和

    371. 两整数之和 不使用运算符 + 和 - ​​​​​​​,计算两整数 ​​​​​​​a .b ​​​​​​​之和. 示例 1: 输入: a = 1, b = 2 输出: 3 示例 2: 输入: ...

  2. Leetcode 371.两整数之和 By Python

    不使用运算符 + 和 - ,计算两整数 a .b 之和. 示例 1: 输入: a = 1, b = 2 输出: 3 示例 2: 输入: a = -2, b = 3 输出: 1 思路 比如\(5+6=1 ...

  3. leetcode 371两整数之和

    class Solution { public: int getSum(int a, int b) { long long carry=b; ){ carry=a&b; a=a^b; b=(c ...

  4. leetcode python两整数之和

    # Leetcode 371 两整数之和***### 题目描述 **不使用**运算符 `+` 和 `-` ​​​​​​​,计算两整数 `​​​​​​​a `.`b` ​​​​​​​之和. **示例1: ...

  5. 力扣(LeetCode)两整数之和 个人题解

    不使用运算符 + 和 - ​​​​​​​,计算两整数 ​​​​​​​a .b ​​​​​​​之和. 示例 1: 输入: a = 1, b = 2 输出: 3 示例 2: 输入: a = -2, b = ...

  6. LeetCode 371两数之和

    题目描述: 不使用运算符 + 和 - ​​​​​​​,计算两整数 ​​​​​​​a .b ​​​​​​​之和. 思路: 既然不能使用运算符操作就要考虑到,位运算的加法. 加法有进位的时候和不进位的时候 ...

  7. Leecode刷题之旅-C语言/python-349两整数之和

    /* * @lc app=leetcode.cn id=371 lang=c * * [371] 两整数之和 * * https://leetcode-cn.com/problems/sum-of-t ...

  8. 前端与算法 leetcode 1. 两数之和

    目录 # 前端与算法 leetcode 1. 两数之和 题目描述 概要 提示 解析 解法一:暴力法 解法二:HashMap法 算法 传入[1, 2], [11, 1, 2, 3, 2]的运行结果 执行 ...

  9. LeetCode:两数之和、三数之和、四数之和

    LeetCode:两数之和.三数之和.四数之和 多数之和问题,利用哈希集合减少时间复杂度以及多指针收缩窗口的巧妙解法 No.1 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在 ...

  10. C#求任意两整数之和

    2019.9.11 作业要求: 求出任意两整数之和 解决方案: using System; using System.Collections.Generic; using System.Linq; u ...

随机推荐

  1. Python3 tkinter基础 LabelFrame Radiobutton 形成两组不相互限制的单选按钮

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. 从Hello World说起(Dart)到“几乎所有东西都是Widget”小部件。

    import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); class MyApp extends S ...

  3. RabbitMQ 入门指南——安装

    RabbitMQ好文 Rabbitmq Java Client Api详解 tohxyblog-博客园-rabbitMQ教程系列 robertohuang-CSDN-rabbitMQ教程系列 Rabb ...

  4. centos6.8下源码编译安装tmux

    1. 获取源码 git clone https://github.com/tmux/tmux.git ~/tmux 2. 准备工作 2.1 安装ncurses开发库 yum install ncurs ...

  5. HDU 4825 Xor Sum(01字典树)题解

    思路:先把所有数字存进字典树,然后从最高位贪心. 代码: #include<set> #include<map> #include<stack> #include& ...

  6. AT2442 フェーン現象 (Foehn Phenomena)

    题目地址 原题地址 题解 其实就是一个区间加,单点查询的问题 当然可以线段树/树状数组做,但是这两个做法要分类讨论所以代码会比较多 我们考虑一种更简便的做法 差分! 因为温度只和海拔差有关,这相当于题 ...

  7. android 控件获取 获取焦点

    控件.setEnabled(true);控件.setFocusable(true);控件.setFocusableInTouchMode(true);控件.requestFocus();控件.requ ...

  8. (zhuan) Building Convolutional Neural Networks with Tensorflow

    Ahmet Taspinar Home About Contact Building Convolutional Neural Networks with Tensorflow Posted on a ...

  9. 剥开比原看代码03:比原是如何监听p2p端口的

    作者:freewind 比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchai ...

  10. using Redis in .net core

    Using Redis Cache in .net Core Distributed Cache using Redis and ASP.NET Core ASP.NET Core Data Prot ...