小编ueg*_*990的帖子

使用迭代的字符串排列

我试图找到给定字符串的排列,但我想使用迭代.我在网上找到的递归解决方案,我确实理解它,但将其转换为迭代解决方案实际上并没有成功.下面我附上了我的代码.我真的很感激帮助:

public static void combString(String s) {
    char[] a = new char[s.length()];
    //String temp = "";
    for(int i = 0; i < s.length(); i++) {
        a[i] = s.charAt(i);
    }
    for(int i = 0; i < s.length(); i++) {
        String temp = "" + a[i];    

        for(int j = 0; j < s.length();j++) {
            //int k = j;
            if(i != j) {
                System.out.println(j);
                temp += s.substring(0,j) + s.substring(j+1,s.length());
            }               
        }
        System.out.println(temp);
    }
}
Run Code Online (Sandbox Code Playgroud)

java permutation

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

Amazon AWS EC2 - 获取 .cer 文件而不是 .pem

当我从 Security Credentials 下载我的私钥文件时,我得到了一个 .cer 文件而不是 .pem。我尝试使用它通过 ssh 连接到我的 ec2 实例,但我不断收到:

密码错误,请重试 pk-xxxxxxxxxxx

是因为我有一个 .cer 文件还是因为我需要密码?我不知道什么是密码。如果我能尽快得到帮助,我将不胜感激。我想我将从 X.509 获得的 .cer 文件与我需要的 ssh 文件混淆了。但问题是我从来没有得到 .pem 文件,只有 .cer 文件

ssh amazon-ec2 amazon-web-services

8
推荐指数
3
解决办法
5791
查看次数

二叉树中最低的共同祖先

以下是我对二进制搜索树的最低共同祖先的实现.我有两个问题:

1)时间复杂度为O(n),空间复杂度为O(n)更差情况,但如果BST平衡,则时间和空间的O(logn)平均情况.那是对的吗?2)我如何将我的解决方案扩展到二叉树而不仅仅是二叉搜索树.

希望早日收到你的消息.

//The function findOrQueue is to enqueue all elements upto target node to a queue
public void findOrQueue(Node target, Node top, LLQueue q) {
    int cmp = target.getData().compareTo(top.getData()); 
    if(cmp == 0) {
        q.enqueue(top);
        return ;
    }
    else if (cmp < 0) {
        q.enqueue(top);
        findOrQueue(target, top.getLeftChild(),q);
    }
    else {
        q.enqueue(top);
        findOrQueue(target, top.getRightChild(),q);
   }
}

public Node LCA(Node n1, Node n2) throws QueueEmptyException {
    LLQueue q1 = new LLQueue();
    LLQueue q2 = new LLQueue();
    findOrQueue(n1,getRoot(),q1);
    findOrQueue(n2,getRoot(),q2);
    Node t = null; …
Run Code Online (Sandbox Code Playgroud)

java binary-tree

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

从Java调用PostgreSQL中的存储过程

我编写了一个存储过程,我想用Java调用它.但我不认为它能够对我通过的查询做任何事情.以下是我的java代码:

String QUERY_LOCATION = "select (license_plate) as test from carInst( (select     category_name from reservation where rid = ?) , (select lname from reservation where rid =  ?))";  
        //PreparedStatement check_location = null;
        PreparedStatement check_location = connection.prepareStatement(QUERY_LOCATION);
        check_location.setInt(1, rid);
        check_location.setInt(2, rid);
        rs = check_location.executeQuery();
        if (rs.next()) {
            System.out.print("Car found: "+rs.getString("test")+"\n");
            license_plate = rs.getString("test");
            update_reservation.setString(5, license_plate);

            bool = false;
        } else {
            System.out
                    .print("There is no car available\n");
        }
Run Code Online (Sandbox Code Playgroud)

以下是我用PL/pgSQL(PostgreSQL)编写的存储过程:

CREATE OR REPLACE FUNCTION carInst(cname varchar(20), loc varchar(20) ) 
RETURNS TABLE (license_plate varchar(6) …
Run Code Online (Sandbox Code Playgroud)

java sql postgresql stored-procedures plpgsql

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