Added accepted solutions for leetcode number 1 and 2 problems
This commit is contained in:
56
main.cpp
Normal file
56
main.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "1-two-sum.cpp"
|
||||
#include "2-add-two-numbers.cpp"
|
||||
|
||||
int main() {
|
||||
TwoSumSolution twoSumSolution;
|
||||
auto v = std::vector<int>{11, 2, 8, 0, 35, 7, 15};
|
||||
auto res = twoSumSolution.twoSum(v, 9);
|
||||
std::cout << "Result: ";
|
||||
for (auto index : res) {
|
||||
std::cout << index << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
AddTwoNumbersSolution addTwoNumbersSolution;
|
||||
ListNode *l1 = new ListNode(2);
|
||||
l1->next = new ListNode(4);
|
||||
l1->next->next = new ListNode(3);
|
||||
|
||||
ListNode *l2 = new ListNode(5);
|
||||
l2->next = new ListNode(6);
|
||||
l2->next->next = new ListNode(4);
|
||||
auto resList = addTwoNumbersSolution.addTwoNumbers(l1, l2);
|
||||
std::cout << "addTwoNumbers: ";
|
||||
ListNode *listPtr = resList;
|
||||
while (listPtr) {
|
||||
std::cout << listPtr->val << " ";
|
||||
listPtr = listPtr->next;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
ListNode *l3 = new ListNode(9);
|
||||
l3->next = new ListNode(9);
|
||||
l3->next->next = new ListNode(9);
|
||||
l3->next->next->next = new ListNode(9);
|
||||
l3->next->next->next->next = new ListNode(9);
|
||||
l3->next->next->next->next->next = new ListNode(9);
|
||||
l3->next->next->next->next->next->next = new ListNode(9);
|
||||
|
||||
ListNode *l4 = new ListNode(9);
|
||||
l4->next = new ListNode(9);
|
||||
l4->next->next = new ListNode(9);
|
||||
l4->next->next->next = new ListNode(9);
|
||||
|
||||
resList = addTwoNumbersSolution.addTwoNumbers(l3, l4);
|
||||
std::cout << "addTwoNumbers: ";
|
||||
listPtr = resList;
|
||||
while (listPtr) {
|
||||
std::cout << listPtr->val << " ";
|
||||
listPtr = listPtr->next;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user