File tree Expand file tree Collapse file tree 4 files changed +30
-36
lines changed
Expand file tree Collapse file tree 4 files changed +30
-36
lines changed Original file line number Diff line number Diff line change @@ -17,42 +17,39 @@ class Trie {
1717 }
1818
1919 insert ( word ) {
20- let curr = this . root
20+ let node = this . root
2121
2222 for ( const char of word ) {
23- if ( ! ( char in curr . children ) ) {
24- curr . children [ char ] = new TrieNode ( )
23+ if ( ! ( char in node . children ) ) {
24+ node . children [ char ] = new TrieNode ( )
2525 }
26-
27- curr = curr . children [ char ]
26+ node = node . children [ char ]
2827 }
2928
30- curr . isWord = true
29+ node . isWord = true
3130 }
3231
3332 search ( word ) {
34- let curr = this . root
33+ let node = this . root
3534
3635 for ( const char of word ) {
37- if ( ! ( char in curr . children ) ) {
36+ if ( ! ( char in node . children ) ) {
3837 return false
3938 }
40-
41- curr = curr . children [ char ]
39+ node = node . children [ char ]
4240 }
4341
44- return curr . isWord
42+ return node . isWord
4543 }
4644
4745 startsWith ( prefix ) {
48- let curr = this . root
46+ let node = this . root
4947
5048 for ( const char of prefix ) {
51- if ( ! ( char in curr . children ) ) {
49+ if ( ! ( char in node . children ) ) {
5250 return false
5351 }
54-
55- curr = curr . children [ char ]
52+ node = node . children [ char ]
5653 }
5754
5855 return true
Original file line number Diff line number Diff line change 11const fn = ( head ) => {
2- let curr = head
32 let prev = null
3+ let curr = head
44
55 while ( curr ) {
6- let nextNode = curr . next
6+ let next = curr . next
77 curr . next = prev
88 prev = curr
9- curr = nextNode
9+ curr = next
1010 }
1111
1212 return prev
Original file line number Diff line number Diff line change @@ -13,35 +13,32 @@ def build(self, words: list[str]) -> None:
1313 self .insert (word )
1414
1515 def insert (self , word : str ) -> None :
16- curr = self .root
16+ node = self .root
1717
1818 for char in word :
19- if char not in curr .children :
20- curr .children [char ] = TrieNode ()
19+ if char not in node .children :
20+ node .children [char ] = TrieNode ()
21+ node = node .children [char ]
2122
22- curr = curr .children [char ]
23-
24- curr .is_word = True
23+ node .is_word = True
2524
2625 def search (self , word : str ) -> bool :
27- curr = self .root
26+ node = self .root
2827
2928 for char in word :
30- if char not in curr .children :
29+ if char not in node .children :
3130 return False
31+ node = node .children [char ]
3232
33- curr = curr .children [char ]
34-
35- return curr .is_word
33+ return node .is_word
3634
3735 def starts_with (self , prefix : str ) -> bool :
38- curr = self .root
36+ node = self .root
3937
4038 for char in prefix :
41- if char not in curr .children :
39+ if char not in node .children :
4240 return False
43-
44- curr = curr .children [char ]
41+ node = node .children [char ]
4542
4643 return True
4744
Original file line number Diff line number Diff line change 11def fn (head ):
2- curr = head
32 prev = None
3+ curr = head
44
55 while curr :
6- next_node = curr .next
6+ nxt = curr .next
77 curr .next = prev
88 prev = curr
9- curr = next_node
9+ curr = nxt
1010
1111 return prev
You can’t perform that action at this time.
0 commit comments