Skip to content

Commit 0b06dd4

Browse files
committed
add 46, 65, update 146
1 parent e33a894 commit 0b06dd4

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

0046-permutations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
46. Permutations
3+
4+
Submitted: January 23, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 17.71 MB (beats 60.66%)
8+
"""
9+
10+
class Solution:
11+
def permute(self, nums: List[int]) -> List[List[int]]:
12+
return list(permutations(nums))

0065-valid-number.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 65. Valid Number
2+
3+
## Approach
4+
5+
I used the regular expression shown below:
6+
7+
```regex
8+
(\+|-)?(\d+\.?|(\d+)?\.\d+)((e|E)(\+|-)?\d+)?
9+
```
10+
11+
### Breakdown of Regex
12+
13+
`(\+|-)?` - an optional plus (`+`) or minus (`-`) sign
14+
`(\d+\.?|(\d+)?\.\d+)` - the digits, matches one of either:
15+
- `\d+\.?` - at least one numeric digit and optionally a following decimal dot (e.g. `123`, `123.`)
16+
- `(\d+)?\.\d+` - a decimal dot and at least one numeric digit, optionally preceded by digits (e.g. `0.33`, `.33`)
17+
`((e|E)(\+|-)?\d+)?` - the exponent:
18+
- `(e|E)` matches either uppercase or lowercase `e`
19+
- `(\+|-)` - see above
20+
- `\d+` - at least one numeric digit
21+
- the `?` at the end makes it optional
22+
23+
## Code
24+
25+
```python3
26+
class Solution:
27+
def isNumber(self, s: str) -> bool:
28+
return bool(re.fullmatch(r'(\+|-)?(\d+\.?|(\d+)?\.\d+)((e|E)(\+|-)?\d+)?', s))
29+
```

0065-valid-number.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
65. Valid Number
3+
4+
Submitted: January 23, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 17.60 MB (beats 49.99%)
8+
"""
9+
10+
class Solution:
11+
def isNumber(self, s: str) -> bool:
12+
return bool(re.fullmatch(r'(\+|-)?(\d+\.?|(\d+)?\.\d+)((e|E)(\+|-)?\d+)?', s))

0146-lru-cache.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
146. LRU Cache
3+
4+
Submitted: January 23, 2025
5+
6+
Runtime: 40 ms (beats 98.63%)
7+
Memory: 111.70 MB (beats 89.29%)
8+
*/
9+
10+
class LRUCache extends LinkedHashMap<Integer, Integer> {
11+
12+
private final int maxSize;
13+
14+
15+
LRUCache(int maxSize) {
16+
super(maxSize, 0.75f, true); // 0.75f is default load factor; true is for accessOrder
17+
this.maxSize = maxSize;
18+
}
19+
20+
public int get(int key) {
21+
return getOrDefault(key, -1);
22+
}
23+
24+
@Override
25+
protected boolean removeEldestEntry(Map.Entry<Integer, Integer> ignore) {
26+
return size() > maxSize;
27+
}
28+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy