Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Guardiaans committed Jul 30, 2022
0 parents commit f0f7db5
Show file tree
Hide file tree
Showing 19 changed files with 515 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
31 changes: 31 additions & 0 deletions cpp/1.two-sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* @lc app=leetcode id=1 lang=cpp
*
* [1] Two Sum
*/

// @lc code=start
class Solution
{
public:
vector<int> twoSum(vector<int> &nums, int target)
{
std::cout << "twoSum" << std::endl;
std::unordered_map<int, int> map;
for (int i = 0; i < nums.size(); i++)
{
map[nums[i]] = i;
}

for (int i = 0; i < nums.size(); i++)
{
int complement = target - nums[i];
if (map.find(complement) != map.end() && map[complement] != i)
{
return {i, map[complement]};
}
}
return {};
}
};
// @lc code=end
18 changes: 18 additions & 0 deletions cpp/13.roman-to-integer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* @lc app=leetcode id=13 lang=cpp
*
* [13] Roman to Integer
*/
#include <iostream>
#include <string>
// @lc code=start
class Solution
{
public:
int romanToInt(string s)
{
std::cout >> s;
return 0;
}
};
// @lc code=end
16 changes: 16 additions & 0 deletions cpp/20.valid-parentheses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* @lc app=leetcode id=20 lang=cpp
*
* [20] Valid Parentheses
*/
#include <stdio.h>
#include <string>
// @lc code=start
class Solution
{
public:
bool isValid(string s)
{
}
};
// @lc code=end
79 changes: 79 additions & 0 deletions cpp/21.merge-two-sorted-lists.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* @lc app=leetcode id=21 lang=cpp
*
* [21] Merge Two Sorted Lists
*/

// @lc code=start
/**
* Definition for singly-linked list.
* 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) {}
* };
*/

#include <iostream>

class Solution
{
public:
ListNode *mergeTwoLists(ListNode *list1, ListNode *list2)
{

if (list1 == nullptr)
return list2;
if (list2 == nullptr)
return list1;

ListNode *head = nullptr;
ListNode *tail = nullptr;

while (list1 != nullptr && list2 != nullptr)
{
if (list1->val < list2->val)
{
if (head == nullptr)
{
head = list1;
tail = list1;
}
else
{
tail->next = list1;
tail = tail->next;
}
list1 = list1->next;
}
else
{
if (head == nullptr)
{
head = list2;
tail = list2;
}
else
{
tail->next = list2;
tail = tail->next;
}
list2 = list2->next;
}
}

if (list1 == nullptr)
{
tail->next = list2;
}
else
{
tail->next = list1;
}

return head;
}
};
// @lc code=end
38 changes: 38 additions & 0 deletions java/20.valid-parentheses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.Stack;

/*
* @lc app=leetcode id=20 lang=java
*
* [20] Valid Parentheses
*/

// @lc code=start
class Solution {
public boolean isValid(String s) {
Stack<Character> stack = new Stack<>();
for (char c : s.toCharArray()) {
// if the character is a closing bracket, check if the stack is empty or not
// if the stack is empty, it means the string is not valid
if (c == '(' || c == '[' || c == '{') {
stack.push(c);
} else {
if (stack.isEmpty()) {
return false;
}
char top = stack.pop();
if (c == ')' && top != '(') {
return false;
}
if (c == ']' && top != '[') {
return false;
}
if (c == '}' && top != '{') {
return false;
}
}
}
return stack.isEmpty();

}
}
// @lc code=end
25 changes: 25 additions & 0 deletions java/21.merge-two-sorted-lists.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

/*
* @lc app=leetcode id=21 lang=java
*
* [21] Merge Two Sorted Lists
*/
import java.util.*;

// @lc code=start
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {

}
}
// @lc code=end
14 changes: 14 additions & 0 deletions java/387.first-unique-character-in-a-string.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* @lc app=leetcode id=387 lang=java
*
* [387] First Unique Character in a String
*/

// @lc code=start
class Solution {
public int firstUniqChar(String s) {

}
}
// @lc code=end

34 changes: 34 additions & 0 deletions js/13.roman-to-integer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* @lc app=leetcode id=13 lang=javascript
*
* [13] Roman to Integer
*/

// @lc code=start
/**
* @param {string} s
* @return {number}
*/
var romanToInt = function (s) {
const map = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000,
};
let result = 0;
for (let i = 0; i < s.length; i++) {
const cur = s[i];
const next = s[i + 1];
if (map[cur] < map[next]) {
result -= map[cur];
} else {
result += map[cur];
}
}
return result;
};
// @lc code=end
24 changes: 24 additions & 0 deletions js/14.longest-common-prefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* @lc app=leetcode id=14 lang=javascript
*
* [14] Longest Common Prefix
*/

// @lc code=start
/**
* @param {string[]} strs
* @return {string}
*/
var longestCommonPrefix = function (strs) {
if (strs.length === 0) return "";
if (strs.length === 1) return strs[0];
let prefix = strs[0];
for (let i = 1; i < strs.length; i++) {
while (strs[i].indexOf(prefix) !== 0) {
prefix = prefix.slice(0, prefix.length - 1);
if (prefix.length === 0) return "";
}
}
return prefix;
};
// @lc code=end
51 changes: 51 additions & 0 deletions js/2043.simple-bank-system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* @lc app=leetcode id=2043 lang=javascript
*
* [2043] Simple Bank System
*/

// @lc code=start
/**
* @param {number[]} balance
*/
var Bank = function(balance) {

};

/**
* @param {number} account1
* @param {number} account2
* @param {number} money
* @return {boolean}
*/
Bank.prototype.transfer = function(account1, account2, money) {

};

/**
* @param {number} account
* @param {number} money
* @return {boolean}
*/
Bank.prototype.deposit = function(account, money) {

};

/**
* @param {number} account
* @param {number} money
* @return {boolean}
*/
Bank.prototype.withdraw = function(account, money) {

};

/**
* Your Bank object will be instantiated and called as such:
* var obj = new Bank(balance)
* var param_1 = obj.transfer(account1,account2,money)
* var param_2 = obj.deposit(account,money)
* var param_3 = obj.withdraw(account,money)
*/
// @lc code=end

24 changes: 24 additions & 0 deletions js/21.merge-two-sorted-lists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* @lc app=leetcode id=21 lang=javascript
*
* [21] Merge Two Sorted Lists
*/

// @lc code=start
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} list1
* @param {ListNode} list2
* @return {ListNode}
*/
var mergeTwoLists = function(list1, list2) {

};
// @lc code=end

16 changes: 16 additions & 0 deletions js/2103.rings-and-rods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* @lc app=leetcode id=2103 lang=javascript
*
* [2103] Rings and Rods
*/

// @lc code=start
/**
* @param {string} rings
* @return {number}
*/
var countPoints = function(rings) {

};
// @lc code=end

Loading

0 comments on commit f0f7db5

Please sign in to comment.