File tree Expand file tree Collapse file tree 4 files changed +52
-13
lines changed
Expand file tree Collapse file tree 4 files changed +52
-13
lines changed Original file line number Diff line number Diff line change 44Submitted: December 4, 2024
55
66Runtime: 0 ms (beats 100.00%)
7- Memory: 27.38 MB (beats 18.77 %)
7+ Memory: 27.11 MB (beats 80.00 %)
88*/
99
1010class Solution {
1111public:
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+ };
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 11/*
22535. 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
1010import 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));
You can’t perform that action at this time.
0 commit comments