File tree 4 files changed +52
-13
lines changed
4 files changed +52
-13
lines changed Original file line number Diff line number Diff line change 4
4
Submitted: December 4, 2024
5
5
6
6
Runtime: 0 ms (beats 100.00%)
7
- Memory: 27.38 MB (beats 18.77 %)
7
+ Memory: 27.11 MB (beats 80.00 %)
8
8
*/
9
9
10
10
class Solution {
11
11
public:
12
12
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 ());
18
14
}
19
- };
15
+ };
Original file line number Diff line number Diff line change
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 ]
Original file line number Diff line number Diff line change
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));
Original file line number Diff line number Diff line change 1
1
/*
2
2
535. Encode and Decode TinyURL
3
3
4
- Submitted: October 29, 2024
4
+ Submitted: March 6, 2025
5
5
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 %)
8
8
*/
9
9
10
10
import java .util .HashMap ;
@@ -16,15 +16,15 @@ public class Codec {
16
16
// Encodes a URL to a shortened URL.
17
17
public String encode (String longUrl ) {
18
18
map .put (longUrl .hashCode (), longUrl );
19
- return "http://tinyurl.com/" + longUrl .hashCode ();
19
+ return Integer . toString ( longUrl .hashCode () );
20
20
}
21
21
22
22
// Decodes a shortened URL to its original URL.
23
23
public String decode (String shortUrl ) {
24
- return map .get (Integer .parseInt (shortUrl . substring ( "http://tinyurl.com/" . length ()) ));
24
+ return map .get (Integer .parseInt (shortUrl ));
25
25
}
26
26
}
27
27
28
28
// Your Codec object will be instantiated and called as such:
29
29
// Codec codec = new Codec();
30
- // codec.decode(codec.encode(url));
30
+ // codec.decode(codec.encode(url));
You can’t perform that action at this time.
0 commit comments