You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
2
+
3
+
// Only one letter can be changed at a time
4
+
// Each intermediate word must exist in the word list
5
+
// For example,
6
+
7
+
// Given:
8
+
// beginWord = "hit"
9
+
// endWord = "cog"
10
+
// wordList = ["hot","dot","dog","lot","log"]
11
+
// Return
12
+
// [
13
+
// ["hit","hot","dot","dog","cog"],
14
+
// ["hit","hot","lot","log","cog"]
15
+
// ]
16
+
// Note:
17
+
// All words have the same length.
18
+
// All words contain only lowercase alphabetic characters.
// Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
2
+
3
+
// Only one letter can be changed at a time
4
+
// Each intermediate word must exist in the word list
5
+
// For example,
6
+
7
+
// Given:
8
+
// beginWord = "hit"
9
+
// endWord = "cog"
10
+
// wordList = ["hot","dot","dog","lot","log"]
11
+
// As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog",
12
+
// return its length 5.
13
+
14
+
// Note:
15
+
// Return 0 if there is no such transformation sequence.
16
+
// All words have the same length.
17
+
// All words contain only lowercase alphabetic characters.
Copy file name to clipboardExpand all lines: 146 LRU Cache.js
+6-13Lines changed: 6 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,3 @@
1
-
// Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.
2
-
3
-
// get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
4
-
// set(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
5
1
classNode{
6
2
constructor(key,val){
7
3
this.key=key;
@@ -18,7 +14,7 @@ var LRUCache = function(capacity) {
18
14
this.map=newMap();
19
15
this.head=null;
20
16
this.tail=null;
21
-
this.size=capacity;
17
+
this.capacity=capacity;
22
18
this.curSize=0;
23
19
};
24
20
@@ -27,12 +23,11 @@ var LRUCache = function(capacity) {
0 commit comments