Compare commits
No commits in common. "828069bf1afa4ff5c50b00456eff9c6fa7085aef" and "e4090f9a09f9028c0d45b40f0f8d788dde4d1fed" have entirely different histories.
828069bf1a
...
e4090f9a09
@ -1,75 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
struct ListNode {
|
|
||||||
int val;
|
|
||||||
ListNode *next;
|
|
||||||
ListNode() : val(0), next(nullptr) {}
|
|
||||||
ListNode(int x) : val(x), next(nullptr) {}
|
|
||||||
ListNode(int x, ListNode *next) : val(x), next(next) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Solution
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ListNode *addTwoNumbers(ListNode *l1, ListNode *l2)
|
|
||||||
{
|
|
||||||
ListNode *l3 = new ListNode();
|
|
||||||
ListNode *begin = l3;
|
|
||||||
int carry = 0;
|
|
||||||
while (1) {
|
|
||||||
if (l1 == nullptr && l2 == nullptr) {
|
|
||||||
return begin;
|
|
||||||
} else if (l1 == nullptr) {
|
|
||||||
l3->val = l2->val + carry;
|
|
||||||
l2 = l2->next;
|
|
||||||
if (l3->val > 10) {
|
|
||||||
carry = 1;
|
|
||||||
l3->val -= 10;
|
|
||||||
} else {
|
|
||||||
carry = 0;
|
|
||||||
}
|
|
||||||
if (l2->next == nullptr) {
|
|
||||||
return begin;
|
|
||||||
} else {
|
|
||||||
l3->next = new ListNode();
|
|
||||||
l3 = l3->next;
|
|
||||||
}
|
|
||||||
} else if (l2 == nullptr) {
|
|
||||||
l3->val = l1->val + carry;
|
|
||||||
l1 = l1->next;
|
|
||||||
if (l3->val > 10) {
|
|
||||||
carry = 1;
|
|
||||||
l3->val -= 10;
|
|
||||||
} else {
|
|
||||||
carry = 0;
|
|
||||||
}
|
|
||||||
if (l1->next == nullptr) {
|
|
||||||
return begin;
|
|
||||||
} else {
|
|
||||||
l3->next = new ListNode();
|
|
||||||
l3 = l3->next;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
l3->val = l1->val + l2->val + carry;
|
|
||||||
|
|
||||||
if (l3->val >= 10) {
|
|
||||||
carry = 1;
|
|
||||||
l3->val -= 10;
|
|
||||||
} else {
|
|
||||||
carry = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
l1 = l1->next;
|
|
||||||
l2 = l2->next;
|
|
||||||
l3->next = new ListNode();
|
|
||||||
l3 = l3->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class Solution {
|
|
||||||
public:
|
|
||||||
int waysToSplitArray(vector<int>& nums) {
|
|
||||||
long long sum1 = 0;
|
|
||||||
int lens = nums.size();
|
|
||||||
for(int i = 0; i < lens;i++){
|
|
||||||
sum1 += nums[i];
|
|
||||||
}
|
|
||||||
long long sum2 = 0;
|
|
||||||
int counter = 0;
|
|
||||||
lens--;
|
|
||||||
for(int i = 0; i < lens;i++){
|
|
||||||
sum2 += nums[i];
|
|
||||||
sum1 -= nums[i];
|
|
||||||
if(sum2 >= sum1){
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return counter;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
vector<int> nums = {10,4,-8,7};
|
|
||||||
Solution solution;
|
|
||||||
cout << solution.waysToSplitArray(nums) << endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user