@@ -111,10 +111,22 @@ def _format_author(self, author_data):
111111 author_name = self ._truncate_text (author_name , 15 )
112112 return author_name
113113
114- def _open_solution_url (self , slug ):
114+ def _open_solution_url (self , solution_node ):
115115 """Open solution URL in browser"""
116- if slug :
117- url = f"{ self .LEETCODE_BASE_URL } { slug } "
116+ slug_parts = solution_node .get ("slug" , "" ).split ("-" )
117+ problem_slug = slug_parts [0 ] if len (slug_parts ) > 0 else ""
118+
119+ if len (slug_parts ) > 1 and slug_parts [1 ] == "sum" :
120+ problem_slug = f"{ slug_parts [0 ]} -{ slug_parts [1 ]} "
121+
122+ solution_id = solution_node .get ("topicId" , "" )
123+ title_slug = solution_node .get ("slug" , "" )
124+
125+ if problem_slug and solution_id and title_slug :
126+ url = f"{ self .LEETCODE_BASE_URL } { problem_slug } /solutions/{ solution_id } /{ title_slug } /"
127+ webbrowser .open (url )
128+ elif problem_slug :
129+ url = f"{ self .LEETCODE_BASE_URL } { problem_slug } /"
118130 webbrowser .open (url )
119131
120132 def show_solution (self ):
@@ -139,13 +151,23 @@ def show_solution(self):
139151
140152 for i , solution in enumerate (self .solutions , 1 ):
141153 node = solution .get ("node" , {})
142- slug = node .get ("slug" , "" )
154+
155+ slug_parts = node .get ("slug" , "" ).split ("-" )
156+ problem_slug = slug_parts [0 ] if len (slug_parts ) > 0 else ""
157+
158+ if len (slug_parts ) > 1 and slug_parts [1 ] == "sum" :
159+ problem_slug = f"{ problem_slug } -{ slug_parts [1 ]} "
160+
161+ solution_id = node .get ("topicId" , "" )
162+ title_slug = node .get ("slug" , "" )
143163
144164 title_text = node .get ("title" , "Untitled" )
145165 truncated_title = self ._truncate_text (
146166 title_text , self .COLUMN_WIDTHS ["Title" ] - 3
147167 )
148- title = f"[link={ self .LEETCODE_BASE_URL } { slug } ][{ self .STYLES ['title' ]} ]{ escape (truncated_title )} [/{ self .STYLES ['title' ]} ][/link]"
168+
169+ solution_url = f"{ self .LEETCODE_BASE_URL } { problem_slug } /solutions/{ solution_id } /{ title_slug } /"
170+ title = f"[link={ solution_url } ][{ self .STYLES ['title' ]} ]{ escape (truncated_title )} [/{ self .STYLES ['title' ]} ][/link]"
149171
150172 author_name = self ._format_author (node .get ("author" , {}))
151173 author = f"[{ self .STYLES ['author' ]} ]{ author_name } [/{ self .STYLES ['author' ]} ]"
@@ -170,8 +192,8 @@ def handle_solution_selection(self, index):
170192 """Handle selection of a solution by index (1-based)"""
171193 if 1 <= index <= len (self .solutions ):
172194 solution = self .solutions [index - 1 ]
173- slug = solution .get ("node" , {}). get ( "slug" , "" )
174- if slug :
175- self ._open_solution_url (slug )
195+ node = solution .get ("node" , {})
196+ if node :
197+ self ._open_solution_url (node )
176198 return True
177199 return False
0 commit comments