Line data Source code
1 : // Copyright (c) 2022 The Authors. All rights reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // https://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : // Authors: liubang (it.liubang@gmail.com)
16 : // Created: 2022/01/17 14:50
17 :
18 : #include <gtest/gtest.h>
19 :
20 : namespace {
21 : class Solution {
22 : public:
23 5 : int add(int a, int b) { return b == 0 ? a : add(a ^ b, (unsigned int)(a & b) << 1); }
24 : };
25 : } // namespace
26 :
27 4 : TEST(Leetcode, bu_yong_jia_jian_cheng_chu_zuo_jia_fa_lcof) {
28 1 : Solution s;
29 1 : EXPECT_EQ(3, s.add(1, 2));
30 1 : EXPECT_EQ(10, s.add(5, 5));
31 1 : }
|