小编use*_*542的帖子

Java - 用于替换字符串中的字母的递归

我完全知道字符串是不可变的,不能改变,可以"editabile" - 哦争议!所以我试图得到它,以便在java 中没有字符串的replace()方法,实现字符串中的特定字符串与另一个字符串切换出来的地方.我希望尽可能简单地执行此操作,而无需导入任何util或使用数组.到目前为止,我已经得到它来改变角色,但它没有正确返回,或者,就是......字符串结束.

public static void main(String[] args) {
    String words = "hello world, i am a java program, how are you today?";
    char from = 'a';
    char to = '/';

    replace(s, from, to);
}
public static String replace(String s, char from, char to){
    if (s.length() < 1)
        return s;
    if (s.charAt(0) == from) {
        s = to + s.substring(1);
    }
    System.out.println(s);
return s.charAt(0) + replace(s.substring(1, s.length()), from, to);
}
Run Code Online (Sandbox Code Playgroud)

java string

6
推荐指数
2
解决办法
2万
查看次数

边列表 vs 邻接表 vs 邻接矩阵

我正在准备创建一个迷宫解决程序。正如这两个问题中所述:图表示:邻接表与矩阵 && 使用邻接表与邻接矩阵的图的大小?他们解释了使用邻接表和邻接矩阵的差异。不幸的是,我无法决定边缘列表与其他两个相比的优缺点,因为我在邻接矩阵和边缘列表上发现的很少。

通过迷宫的相邻列表(我认为)的一个例子是:

insertVertex(V)               : O(1)
insertEdge(Vertex, Vertex, E) : O(1)
removeVertex(Vertex)          : O(deg(v))
removeEdge(Edge)              : O(m)
vertices()                    : O(n)
edges()                       : O(m)
areAdjacent(Vertex, Vertex)   : O(min(deg(v),deg(w))
endVertices(Edge)             : O(1)
incidentEdges(Vertex)         : O(deg(v))
space complexity              : O(n+m)
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,对于这个迷宫求解问题,哪一个具有最佳时间成本的边列表、邻接表或邻接矩阵?

algorithm graph

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

FluentAssertions,确保IEnumerable只包含单个元素

我正在编写单元测试,我有一些看起来像这样的东西:

[Fact]
public void GetFoos_only_gets_foo1()
{
    _foo1.included = true; //Foo object
    _foo2.included = false; //Foo object
    _sut.GetFoos().Should().OnlyContain(_foo1); // this doesn't work, is there a specific syntax to use?
}
Run Code Online (Sandbox Code Playgroud)

并且GetFoos()返回和IEnumberable<Foo>

c# xunit fluent-assertions

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

keySet和entrySet需要定义的方法?

这是相当荒谬的,我不确定为什么会发生这种情况,但每当我尝试使用.keySet或者.entrySet我在Eclipse中得到错误时都会为它创建一个新方法.

java treemap

-1
推荐指数
1
解决办法
87
查看次数

标签 统计

java ×2

algorithm ×1

c# ×1

fluent-assertions ×1

graph ×1

string ×1

treemap ×1

xunit ×1