小编Joh*_*ana的帖子

当我使用文本文件时,为什么我的代码打印空数组([])?

当我以这种方式定义我的数组字符串时:

String[] X = {"X","M","J","Y","A","U","Z"};
String[] Y = {"M","Z","J","A","W","X","U"};
Run Code Online (Sandbox Code Playgroud)

我的代码有效,它打印[M, J, A, U]出最长公共子序列XY但是当我为具有相同输入的字符串数组定义文本文件时,我的代码打印一个空数组[]。我该如何解决这个问题?

    public class LCS   {
    // Function to find LCS of String X[0..m-1] and Y[0..n-1]
    public static String A(String[] x, String[] y, int m, int n, int[][] T)
    {
        // return empty string if we have reached the end of
        // either sequence
        if (m == 0 || n == 0) {
            return new String();
        }
        // if last character …
Run Code Online (Sandbox Code Playgroud)

java arrays bufferedreader

5
推荐指数
1
解决办法
123
查看次数

如何在高阶函数haskell中使用Maybe?

我想解决以下问题,其中 f 不返回任何内容,然后删除第一个元素。如果 f 返回 Just x,则第一个元素随 x 改变。我下面的答案对 Nothing 正确,但我无法理解如何在函数内部区分 Nothing 和 Just

change:: (a -> Maybe a) -> [a] -> [a]
change f [] = []
change f (x:xs) = xs
Run Code Online (Sandbox Code Playgroud)

改变(\x -> 没有) [1..5] == [2..5]

change(\x -> Just 10) [1,2,3] == [10,2,3]

haskell higher-order-functions

2
推荐指数
1
解决办法
70
查看次数