Description Polycarp has guessed three positive integers \(a\), \(b\) and \(c\). He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order - their pairwise sums (three numbers) and sum of all three numbers (one n…
Content 已知有三个正整数 \(a,b,c\),现在给出 \(a+b,a+c,b+c,a+b+c\)(不保证有序)的值,试求出 \(a,b,c\). 数据范围:\(2\leqslant a+b,a+c,b+c,a+b+c\leqslant 10^9\). Solution 肯定地,如果是无序的话,那么我们肯定要先对这四个值排序,得到: \[\begin{cases}x_1=a+b\\x_2=a+c\\x_3=b+c\\x_4=a+b+c\end{cases} \] 那么,运用加减消元,我们…
题目: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two num…
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.gitbooks.io/leetbook/ ` 2.Add Two Numbers [M] Add Two Numbers M 题目 思路 代码 更精巧的代码 题目 You are given two linked lists representing two non-negative numbers. The…
1.题目描述 2.问题分析 使的 A[i] = i+1 ,最后检查不满足这个条件的i+1 .即为缺失的值. 3.代码 vector<int> findDisappearedNumbers(vector<int>& nums) { ; i < nums.size() ; ++i ){ ] ){ swap( nums[i] , nums[nums[i] - ] ); i--; } } vector<int> result ; ; i < nums.siz…
1.题目描述 2.分析 首先将链表翻转,然后做加法. 最后将结果链表翻转. 3.代码 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode* L1 = reverseList( l1 ); ListNode* L2 = reverseList( l2 ); ListNode* head = ); ListNode* result = head; ListNode* p1 = L1; ListNode* p2 = L2; ;…
1.题目描述 2.题目描述 题目思路可以参考合并单链表的思路,定义一个全局 进位标志,如果两个数值相加得到需要进位,则将进位标志置为1 . 3.代码 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode* head = ) ; ListNode* result = head; ListNode* p1 = l1; ListNode* p2 = l2; ; while( p1 != NULL && p2 != NULL…
1.题目描述 2.题目分析 简单题目,只要挨个判断该数是不是满足条件即可. 3.代码 vector<int> selfDividingNumbers(int left, int right) { vector<int> ans; for(int i = left; i <= right; i++) { if( isDividingNumber(i) ) ans.push_back(i); } return ans; } bool isDividingNumber( int n…
题目大意:使用链表表示的两个整数,计算出其和,以同样的形式返回. Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 觉得做OJ最大的问题是有时看不懂题目. 其实是这样的,一个链表代表一个非负整数数,是从右往左看的: (2 -> 4 -> 3) = 342: (5 -> 6 -> 4)=465: 342+465=7 -> 0 -> 8=807: 逆序其实是很大很大的便利!!…
又是愚人节题目qwq-- 说一下题意吧: 把第1个数翻转后加第二个数 具体思路: 1.定义变量,进行输入 int a,b; cin>>a>>b; 2.定义一个变量c,作为存储第1个数的翻转 int c; 3.写出翻转第一个数的代码 while(b!=0) { c*=10; c+=b%10; b/=10; } c*10指把c扩大10倍,最后一位变成0 c+=b%10指将b目前的个位数赋值给c b/=10把b除以10最后一位则为原来的十位数 4.输出a+c即可 代码如下: #inclu…