如何生成一个n-gram的字符串,如:
String Input="This is my car."
Run Code Online (Sandbox Code Playgroud)
我想用这个输入生成n-gram:
Input Ngram size = 3
Run Code Online (Sandbox Code Playgroud)
输出应该是:
This
is
my
car
This is
is my
my car
This is my
is my car
Run Code Online (Sandbox Code Playgroud)
在Java中给出一些想法,如何实现它或者是否有可用的库.
我正在尝试使用这个NGramTokenizer,但它给出了n-gram的字符序列,我想要n-gram的单词序列.
我试图实现一个硬币问题,问题规范是这样的
创建一个函数来计算可用于给定金额的所有可能的硬币组合.
All possible combinations for given amount=15, coin types=1 6 7
1) 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2) 1,1,1,1,1,1,1,1,1,6,
3) 1,1,1,1,1,1,1,1,7,
4) 1,1,1,6,6,
5) 1,1,6,7,
6) 1,7,7,
Run Code Online (Sandbox Code Playgroud)
功能原型:
int findCombinationsCount(int amount, int coins[])
Run Code Online (Sandbox Code Playgroud)
假设硬币阵列已排序.对于上面的例子,这个函数应该返回6.
任何人都指导我如何实现这个?
您好,我正在尝试实现hasPathSum()
给定数字的方法,根到叶节点之间是否存在任何路径。
我从斯坦福网站获得了这段代码。我认为这是错误的
/**
Given a tree and a sum, returns true if there is a path from the root
down to a leaf, such that adding up all the values along the path
equals the given sum.
Strategy: subtract the node value from the sum when recurring down,
and check to see if the sum is 0 when you run out of tree.
*/
boolean hasPathSum(Node node, int sum) {
// return true if we run out of …Run Code Online (Sandbox Code Playgroud) 在使用GSON API将Java对象转换为Json字符串时,如果任何带注释的属性为null,我还希望失败此Json转换.
例如
public class Order{
@SerializedName("orderId")
@Expose
@Required
private Integer id;
//getter & setter available for id
}
Run Code Online (Sandbox Code Playgroud)
就像我在做的那样
Order order = new Order();
JSONObject jsonobj = new JSONObject(gson.toJson(order));
Run Code Online (Sandbox Code Playgroud)
如果任何@Required属性为null,我想让上面的Java失败到Json转换这是否可以使用GSON?
为什么java不会阻止你实例化任何单例类对象?
我试图创建Void类的对象
java.lang.Void
Run Code Online (Sandbox Code Playgroud)
我写了这段代码来创建两个实例
try{
Class clazz = Void.class;
Constructor cons = clazz.getDeclaredConstructor();
cons.setAccessible(true);
Void s2 = (Void) cons.newInstance();
System.out.println(s2);
Void s3 = (Void) cons.newInstance();
System.out.println(s3);
}catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释 - 为什么这在java中是允许的?
我想用php和mysql创建一个应用程序.
假设我正在进行api调用并获取网址列表.我想存储这些网址,每个网址应该有一个uniqe id(即数字),以便我可以将该ID传递给某个页面,我可以从我的数据库中获取网址.
假设我做了一个api调用得到五个关键字"xyz"的网址,我得到了以下网址和各自的标题
google.com/abc1.html title1
google.com/abc2.html title2
google.com/abc3.html title3
google.com/abc4.html title4
Run Code Online (Sandbox Code Playgroud)
所以我想生成每个网址的唯一ID
id1 google.com/abc1.html title1
id2 google.com/abc2.html title2
id3 google.com/abc3.html title3
id4 google.com/abc4.html title4
Run Code Online (Sandbox Code Playgroud)
约束是url应该是唯一的
数据库可以容纳12个左右的URL.
你能指导我如何实现吗?还给出了一些优化指南
谢谢