Skip to content

Commit 4a7ff6f

Browse files
committed
feat: Solved 10 Leetcode problems
* Solved 6 Leetcode problems from the Top 50 SQL study plan * Solved 4 additional Leetcode problems
1 parent 571060e commit 4a7ff6f

10 files changed

+109
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @param {number[]} nums1
3+
* @param {number[]} nums2
4+
* @return {number[]}
5+
*/
6+
var intersect = function(nums1, nums2) {
7+
const map =new Map()
8+
let value
9+
10+
for(const num of nums1){
11+
value = map.get(num)
12+
map.set(num, (value===undefined)?1:value+1)
13+
}
14+
15+
const intersection=[]
16+
for(const num of nums2)
17+
{
18+
value = map.get(num)
19+
20+
if(value!==undefined){
21+
if(value>1)
22+
map.set(num, value-1)
23+
else if(value===1)
24+
map.delete(num)
25+
26+
intersection.push(num)
27+
}
28+
}
29+
30+
return intersection
31+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[]} arr
3+
* @return {boolean}
4+
*/
5+
var threeConsecutiveOdds = function(arr) {
6+
consecutiveOdds=0
7+
8+
for(let i=0;i<arr.length;i++)
9+
if(arr[i]%2!==1)
10+
consecutiveOdds=0
11+
12+
else if(++consecutiveOdds===3)
13+
return true
14+
15+
return false
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val, next) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.next = (next===undefined ? null : next)
6+
* }
7+
*/
8+
/**
9+
* @param {ListNode} head
10+
* @return {ListNode}
11+
*/
12+
var mergeNodes = function(head) {
13+
let pivotNode=head.next, accum=pivotNode.val,currNode=pivotNode
14+
15+
while((currNode=currNode.next)!==null){
16+
if(currNode.val!==0)
17+
accum+=currNode.val
18+
else
19+
{
20+
pivotNode.val=accum
21+
pivotNode.next=currNode.next
22+
pivotNode=pivotNode.next
23+
accum=0
24+
}
25+
}
26+
27+
return head.next
28+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var minDifference = function(nums) {
6+
const movs=3
7+
8+
if(nums.length<=movs)
9+
return 0
10+
11+
nums.sort((a,b)=>b-a)
12+
13+
const movsList=new Array(movs*2)
14+
for(let i=movs;i>0;i--)
15+
{
16+
movsList.push(nums[movs-i]-nums[nums.length-1-i])
17+
movsList.push(nums[i]-nums[nums.length-1-movs+i])
18+
}
19+
movsList.sort((a,b)=>a-b)
20+
21+
return movsList[0]
22+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Write your MySQL query statement below
2+
SELECT unique_id, name FROM Employees AS e LEFT JOIN EmployeeUNI AS u ON e.id=u.id;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Write your MySQL query statement below
2+
SELECT DISTINCT viewer_id AS id FROM Views WHERE author_id=viewer_id ORDER BY viewer_id;
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Write your MySQL query statement below
2+
SELECT name, population, area FROM World WHERE area>=3000000 OR population>=25000000;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Write your MySQL query statement below
2+
SELECT name From Customer WHERE id NOT IN (SELECT id FROM Customer WHERE referee_id=2);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Write your MySQL query statement below
2+
SELECT tweet_id FROM Tweets WHERE CHAR_LENGTH(content)>15;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Write your MySQL query statement below
2+
SELECT product_id FROM Products WHERE low_fats='Y' AND recyclable='Y';

0 commit comments

Comments
 (0)