我正在求解给定数字n的BST算法,我需要返回小于n的最大值。不幸的是,一旦我找到答案。我的代码没有返回它,但继续循环。我想念什么?谢谢。
setTimeout(function *() {
yield put(showPermissionsNeededWall('Please log in', null));
readTimeLoginBoxShown();
}, 1000 * SHOW_LOGIN_WALL_AFTER_IN_SECONDS);
答案 0 :(得分:0)
很酷的算法。
考虑当不再有左右时会发生什么:
这可能只发生一次,但不再导致最大== self.root.key的出现,因此不在这里
var delegatingHandler = new DelegatingHandlerStub(false);
var httpClient = new HttpClient(delegatingHandler);
var tokenServices = new TokenServices(httpClient)
tokenServices.RequestToken(passwordTokenRequest); //exception
public class TokenServices : ITokenServices
{
private readonly HttpClient _httpClient;
public TokenServices(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<TokenResponse> RequestToken(PasswordTokenRequest request)
{
var response = await _httpClient.RequestPasswordTokenAsync(request);
}
}
public class DelegatingHandlerStub : DelegatingHandler
{
private readonly Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> _handlerFunc;
public DelegatingHandlerStub(bool toThrowException)
{
_handlerFunc = (request, cancellationToken) =>
{
if (toThrowException)
throw new Exception();
return Task.FromResult(request.CreateResponse(HttpStatusCode.OK));
};
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return _handlerFunc(request, cancellationToken);
}
}
namespace IdentityModel.Client
{
public static class HttpClientTokenRequestExtensions
{
public static Task<TokenResponse> RequestPasswordTokenAsync(this HttpMessageInvoker client, PasswordTokenRequest request, CancellationToken cancellationToken = default(CancellationToken));
}
}
这不会发生
if self.root.key < num and self.root.key > largest:
largest = self.root.key
也不会
if self.root.right:
但是
self.root仍然是真实的,所以
if self.root.left:
将永远保持奔跑状态