Skip to content

Commit 389d606

Browse files
committed
add 344, 535, update 344, 535
1 parent 800571a commit 389d606

4 files changed

+52
-13
lines changed

0344-reverse-string.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44
Submitted: December 4, 2024
55
66
Runtime: 0 ms (beats 100.00%)
7-
Memory: 27.38 MB (beats 18.77%)
7+
Memory: 27.11 MB (beats 80.00%)
88
*/
99

1010
class Solution {
1111
public:
1212
void reverseString(vector<char>& s) {
13-
for (int i = 0, n = s.size(); i < n / 2; ++i) {
14-
char temp = s[i];
15-
s[i] = s[n - i - 1];
16-
s[n - i - 1] = temp;
17-
}
13+
reverse(s.begin(), s.end());
1814
}
19-
};
15+
};

0344-reverse-string.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
344. Reverse String
3+
4+
Submitted: March 2, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 23.54 MB (beats 5.63%)
8+
"""
9+
10+
class Solution:
11+
def reverseString(self, s: List[str]) -> None:
12+
"""
13+
Do not return anything, modify s in-place instead.
14+
"""
15+
s[:] = s[::-1]

0535-encode-and-decode-tinyurl.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
535. Encode and Decode TinyURL
3+
4+
Submitted: March 6, 2025
5+
6+
Runtime: 7 ms (beats 21.56%)
7+
Memory: 10.05 MB (beats 52.16%)
8+
*/
9+
10+
class Solution {
11+
vector<string> v;
12+
13+
public:
14+
// Encodes a URL to a shortened URL.
15+
string encode(string longUrl) {
16+
v.push_back(longUrl);
17+
return to_string(v.size() - 1);
18+
}
19+
20+
// Decodes a shortened URL to its original URL.
21+
string decode(string shortUrl) {
22+
return v[stoi(shortUrl)];
23+
}
24+
};
25+
26+
// Your Solution object will be instantiated and called as such:
27+
// Solution solution;
28+
// solution.decode(solution.encode(url));

0535-encode-and-decode-tinyurl.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
22
535. Encode and Decode TinyURL
33
4-
Submitted: October 29, 2024
4+
Submitted: March 6, 2025
55
6-
Runtime: 5 ms (beats 31.19%)
7-
Memory: 43.12 MB (beats 28.30%)
6+
Runtime: 2 ms (beats 69.39%)
7+
Memory: 43.03 MB (beats 55.63%)
88
*/
99

1010
import java.util.HashMap;
@@ -16,15 +16,15 @@ public class Codec {
1616
// Encodes a URL to a shortened URL.
1717
public String encode(String longUrl) {
1818
map.put(longUrl.hashCode(), longUrl);
19-
return "http://tinyurl.com/" + longUrl.hashCode();
19+
return Integer.toString(longUrl.hashCode());
2020
}
2121

2222
// Decodes a shortened URL to its original URL.
2323
public String decode(String shortUrl) {
24-
return map.get(Integer.parseInt(shortUrl.substring("http://tinyurl.com/".length())));
24+
return map.get(Integer.parseInt(shortUrl));
2525
}
2626
}
2727

2828
// Your Codec object will be instantiated and called as such:
2929
// Codec codec = new Codec();
30-
// codec.decode(codec.encode(url));
30+
// codec.decode(codec.encode(url));

0 commit comments

Comments
 (0)