hackerrank Java Data Structures
生活随笔
收集整理的這篇文章主要介紹了
hackerrank Java Data Structures
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
地址:https://www.hackerrank.com/domains/java/java-data-structure
題目https://www.hackerrank.com/challenges/java-list
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*;public class Solution {public static void main(String[] args) {/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scanner in = new Scanner(System.in);int n = in.nextInt();LinkedList<Integer> l = new LinkedList<Integer>();for(int i = 0;i < n;i++)l.add(in.nextInt());int q = in.nextInt();while(q-- > 0){String op = in.next();if(op.equals("Insert")){int x = in.nextInt(),y = in.nextInt();l.add(x,y);}else{int x = in.nextInt();l.remove(x);}}for(int x : l)System.out.print(x + " "); } }題目:https://www.hackerrank.com/challenges/phone-book
題意:使用map
思路:以前好像沒怎么用過.nextLine()
.nextLine()用來讀入一行數據,這個和C++已經取消的gets相似,都會讀入換行,如果使用前有讀入數據的話,提前讀入空行.nextLine() 防止影響后面的讀入。
代碼:
題目:https://www.hackerrank.com/challenges/java-stack/problem
代碼:
題目:https://www.hackerrank.com/challenges/java-hashset/problem
代碼:
總結
以上是生活随笔為你收集整理的hackerrank Java Data Structures的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在vue.js引用图片的问题
- 下一篇: Java IO File