|
22 | 22 | <img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1700-1799/1797.Design%20Authentication%20Manager/images/copy-of-pc68_q2.png" style="width: 500px; height: 287px;" />
|
23 | 23 | <pre>
|
24 | 24 | <strong>Input</strong>
|
25 |
| -["AuthenticationManager", "<code>renew</code>", "generate", "<code>countUnexpiredTokens</code>", "generate", "<code>renew</code>", "<code>renew</code>", "<code>countUnexpiredTokens</code>"] |
26 |
| -[[5], ["aaa", 1], ["aaa", 2], [6], ["bbb", 7], ["aaa", 8], ["bbb", 10], [15]] |
| 25 | +["AuthenticationManager", "renew", "generate", "countUnexpiredTokens", "generate", "renew", "renew", "countUnexpiredTokens"] |
| 26 | +[[5], ["aaa", 1], ["aaa", 2], [6], ["bbb", 7], ["aaa", 8], ["bbb", 10], [15]] |
27 | 27 | <strong>Output</strong>
|
28 | 28 | [null, null, null, 1, null, null, null, 0]
|
29 | 29 |
|
30 | 30 | <strong>Explanation</strong>
|
31 | 31 | AuthenticationManager authenticationManager = new AuthenticationManager(5); // Constructs the AuthenticationManager with <code>timeToLive</code> = 5 seconds.
|
32 |
| -authenticationManager.<code>renew</code>("aaa", 1); // No token exists with tokenId "aaa" at time 1, so nothing happens. |
33 |
| -authenticationManager.generate("aaa", 2); // Generates a new token with tokenId "aaa" at time 2. |
34 |
| -authenticationManager.<code>countUnexpiredTokens</code>(6); // The token with tokenId "aaa" is the only unexpired one at time 6, so return 1. |
35 |
| -authenticationManager.generate("bbb", 7); // Generates a new token with tokenId "bbb" at time 7. |
36 |
| -authenticationManager.<code>renew</code>("aaa", 8); // The token with tokenId "aaa" expired at time 7, and 8 >= 7, so at time 8 the <code>renew</code> request is ignored, and nothing happens. |
37 |
| -authenticationManager.<code>renew</code>("bbb", 10); // The token with tokenId "bbb" is unexpired at time 10, so the <code>renew</code> request is fulfilled and now the token will expire at time 15. |
38 |
| -authenticationManager.<code>countUnexpiredTokens</code>(15); // The token with tokenId "bbb" expires at time 15, and the token with tokenId "aaa" expired at time 7, so currently no token is unexpired, so return 0. |
| 32 | +authenticationManager.<code>renew</code>("aaa", 1); // No token exists with tokenId "aaa" at time 1, so nothing happens. |
| 33 | +authenticationManager.generate("aaa", 2); // Generates a new token with tokenId "aaa" at time 2. |
| 34 | +authenticationManager.<code>countUnexpiredTokens</code>(6); // The token with tokenId "aaa" is the only unexpired one at time 6, so return 1. |
| 35 | +authenticationManager.generate("bbb", 7); // Generates a new token with tokenId "bbb" at time 7. |
| 36 | +authenticationManager.<code>renew</code>("aaa", 8); // The token with tokenId "aaa" expired at time 7, and 8 >= 7, so at time 8 the <code>renew</code> request is ignored, and nothing happens. |
| 37 | +authenticationManager.<code>renew</code>("bbb", 10); // The token with tokenId "bbb" is unexpired at time 10, so the <code>renew</code> request is fulfilled and now the token will expire at time 15. |
| 38 | +authenticationManager.<code>countUnexpiredTokens</code>(15); // The token with tokenId "bbb" expires at time 15, and the token with tokenId "aaa" expired at time 7, so currently no token is unexpired, so return 0. |
39 | 39 |
|
40 | 40 | </pre>
|
41 | 41 |
|
|
0 commit comments