gpt4 book ai didi

java - 黑客排名 : Illegal static declaration in inner class Solution. 结果

转载 作者:行者123 更新时间:2023-12-02 02:12:02 25 4
gpt4 key购买 nike

大多数时候,当我在 hackerrank 中解决问题时,编译器会给出以下错误:olution.java:81: error: 内部类 Solution.Result 中的非法静态声明public static DoublyLinkedListNode SortedInsert(DoublyLinkedListNode llist, int data) {即使我不写任何一行代码也会发生这种情况。我尝试删除 static 关键字,但它找不到该方法。

  import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {

static class DoublyLinkedListNode {
public int data;
public DoublyLinkedListNode next;
public DoublyLinkedListNode prev;

public DoublyLinkedListNode(int nodeData) {
this.data = nodeData;
this.next = null;
this.prev = null;
}
}

static class DoublyLinkedList {
public DoublyLinkedListNode head;
public DoublyLinkedListNode tail;

public DoublyLinkedList() {
this.head = null;
this.tail = null;
}

public void insertNode(int nodeData) {
DoublyLinkedListNode node = new DoublyLinkedListNode(nodeData);

if (this.head == null) {
this.head = node;
} else {
this.tail.next = node;
node.prev = this.tail;
}

this.tail = node;
}
}

public static void printDoublyLinkedList(DoublyLinkedListNode node, String sep, BufferedWriter bufferedWriter) throws IOException {
while (node != null) {
bufferedWriter.write(String.valueOf(node.data));

node = node.next;

if (node != null) {
bufferedWriter.write(sep);
}
}
}

class Result {

/*
* Complete the 'sortedInsert' function below.
*
* The function is expected to return an INTEGER_DOUBLY_LINKED_LIST.
* The function accepts following parameters:
* 1. INTEGER_DOUBLY_LINKED_LIST llist
* 2. INTEGER data
*/

/*
* For your reference:
*
* DoublyLinkedListNode {
* int data;
* DoublyLinkedListNode next;
* DoublyLinkedListNode prev;
* }
*
*/

public static DoublyLinkedListNode sortedInsert(DoublyLinkedListNode llist, intdata) {
// Write your code here

}

}

private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

int t = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

for (int tItr = 0; tItr < t; tItr++) {
DoublyLinkedList llist = new DoublyLinkedList();

int llistCount = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

for (int i = 0; i < llistCount; i++) {
int llistItem = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

llist.insertNode(llistItem);
}

int data = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

DoublyLinkedListNode llist1 = sortedInsert(llist.head, data);

printDoublyLinkedList(llist1, " ", bufferedWriter);
bufferedWriter.newLine();
}

bufferedWriter.close();

scanner.close();
}
}

最佳答案

 public static DoublyLinkedListNode sortedInsert(DoublyLinkedListNode llist, intdata) {

// Write your code here

}.

将此方法放在外部 结果 内部 解决方案

关于java - 黑客排名 : Illegal static declaration in inner class Solution. 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67618475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com