我需要一个简单的例子来说明如何初始化会话并发送一条FIX消息.我有这个初始代码:
SessionSettings settings = new SessionSettings( new FileInputStream("fix.cfg"));
Application application = new Application(settings);
MessageStoreFactory messageStoreFactory = new FileStoreFactory(settings);
LogFactory logFactory = new ScreenLogFactory( true, true, true);
MessageFactory messageFactory = new DefaultMessageFactory();
Initiator initiator = new SocketInitiator(application, messageStoreFactory, settings, logFactory, messageFactory);
initiator.start();
Run Code Online (Sandbox Code Playgroud) 帮我优化算法.我在数组中有一堆.数组中的每个数字表示父项.根是-1.我需要找到堆的深度.例:
数组是4 -1 4 1 1
答案是3.
这是我的代码
static int findMax(int[] mas) {
int a[] = new int[mas.length];
a[pos] = 1;
int max = 0;
for (int j = 0; j < mas.length; j++) {
for (int i = 0; i < a.length; i++) {
if (a[i] == 0 && a[mas[i]] != 0) {
a[i] = a[mas[i]] + 1;
if (a[i] > max)
max = a[i];
}
}
}
return max;
}
Run Code Online (Sandbox Code Playgroud)
pos位置 - 根位置.
我也用递归解决了这个问题.但测试也给了我"超出时间限制".
static class Node { …Run Code Online (Sandbox Code Playgroud) 我找到了一个带有java谓词功能接口的例子:
BiPredicate<String, String> b1 = String::startsWith;
BiPredicate<String, String> b2 =
(string, prefix) -> string.startsWith(prefix);
System.out.println(b1.test("chicken", "chick"));
System.out.println(b2.test("chicken", "chick"));
Run Code Online (Sandbox Code Playgroud)
我了解 b2 的工作原理 - 很清楚。编译器如何理解如何使用b1方法?方法 boolean startWith(String str) 只有一个参数。String 类没有
boolean startWith(String srt1, String srt2) 方法。