Line data Source code
1 : // Copyright (c) 2024 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 :
17 : #include <gtest/gtest.h>
18 :
19 : namespace {
20 : class Solution {
21 : public:
22 5 : int add(int a, int b) { return b == 0 ? a : add(a ^ b, (unsigned int)(a & b) << 1); }
23 : };
24 : } // namespace
25 :
26 4 : TEST(Leetcode, bu_yong_jia_jian_cheng_chu_zuo_jia_fa_lcof) {
27 1 : Solution s;
28 1 : EXPECT_EQ(3, s.add(1, 2));
29 1 : EXPECT_EQ(10, s.add(5, 5));
30 1 : }
|