Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0923e65

Browse files
authored
add 283, 292, 468, 595, 2621, 3079, 3467, modify 2621
1 parent 3780b25 commit 0923e65

8 files changed

+140
-0
lines changed

0283-move-zeroes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
283. Move Zeroes
3+
4+
Submitted: May 20, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 19.08 MB (beats 9.79%)
8+
"""
9+
10+
class Solution:
11+
def moveZeroes(self, nums: List[int]) -> None:
12+
"""
13+
Do not return anything, modify nums in-place instead.
14+
"""
15+
# technically modifying in place...
16+
nums[:] = [i for i in nums if i != 0] + [0] * nums.count(0)

0292-nim-game.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
292. Nim Game
3+
4+
Submitted: May 20, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 7.80 MB (beats 53.38%)
8+
*/
9+
10+
class Solution {
11+
public:
12+
bool canWinNim(int n) {
13+
return n % 4 != 0;
14+
}
15+
};

0468-validate-ip-address.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
468. Validate IP Address
3+
4+
Submitted: May 20, 2025
5+
6+
Runtime: 1 ms (beats 7.28%)
7+
Memory: 17.78 MB (beats 71.36%)
8+
"""
9+
10+
import re
11+
12+
RE_IPV4_LIKELY = re.compile(r'[0-9]{1,3}(?:\.[0-9]{1,3}){3}')
13+
RE_IPV6 = re.compile(r'(?:[0-9a-f]{1,4})(?::[0-9a-f]{1,4}){7}', re.I)
14+
NO_LEADING_ZEROES = re.compile(r'0|[1-9][0-9]*')
15+
16+
def isIPv4(ip: str) -> bool:
17+
if not RE_IPV4_LIKELY.fullmatch(ip):
18+
return False
19+
return all(0 <= int(n) <= 255 and NO_LEADING_ZEROES.fullmatch(n) for n in ip.split('.'))
20+
21+
def isIPv6(ip: str) -> bool:
22+
return bool(RE_IPV6.fullmatch(ip))
23+
24+
class Solution:
25+
def validIPAddress(self, queryIP: str) -> str:
26+
return (
27+
"IPv4" if isIPv4(queryIP) else (
28+
"IPv6" if isIPv6(queryIP) else "Neither"
29+
)
30+
)

0595-big-countries.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
595. Big Countries
3+
4+
Submitted: May 20, 2025
5+
6+
Runtime: 260 ms (beats 86.70%)
7+
*/
8+
9+
# Write your MySQL query statement below
10+
SELECT name, population, area FROM World
11+
WHERE area >= 3000000 OR population >= 25000000

2621-sleep.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
2621. Sleep
3+
4+
Submitted: May 5, 2025
5+
6+
Runtime: 55 ms (beats 11.05%)
7+
Memory: 54.95 MB (beats 60.28%)
8+
*/
9+
10+
async function sleep(millis: number): Promise<void> {
11+
return new Promise(resolve => setTimeout(resolve, millis));
12+
}
13+
14+
15+
/**
16+
* let t = Date.now()
17+
* sleep(100).then(() => console.log(Date.now() - t)) // 100
18+
*/

2723-add-two-promises.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
2723. Add Two Promises
3+
4+
Submitted: May 20, 2025
5+
6+
Runtime: 54 ms (beats 59.13%)
7+
Memory: 54.12 MB (beats 96.93%)
8+
*/
9+
10+
async function addTwoPromises(
11+
promise1: Promise<number>,
12+
promise2: Promise<number>
13+
): Promise<number> {
14+
return await promise1 + await promise2;
15+
};
16+
17+
/**
18+
* addTwoPromises(Promise.resolve(2), Promise.resolve(2))
19+
* .then(console.log); // 4
20+
*/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
3079. Find the Sum of Encrypted Integers
3+
4+
Submitted: May 20, 2025
5+
6+
Runtime: 54 ms (beats 61.66%)
7+
Memory: 17.88 MB (beats 34.20%)
8+
"""
9+
10+
def encrypt(n: int):
11+
s = str(n)
12+
return int(len(s) * max(s))
13+
14+
class Solution:
15+
def sumOfEncryptedInt(self, nums: List[int]) -> int:
16+
return sum(encrypt(n) for n in nums)

3467-transform-array-by-parity.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
3467. Transform Array by Parity
3+
4+
Submitted: May 20, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 17.67 MB (beats 96.40%)
8+
"""
9+
10+
class Solution:
11+
def transformArray(self, nums: List[int]) -> List[int]:
12+
return sorted(
13+
n % 2 for n in nums
14+
)

0 commit comments

Comments
 (0)