-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f0f7db5
Showing
19 changed files
with
515 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.