题解 | #提取不重复的整数#

提取不重复的整数

https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1

public static String nonRepeated2(InputStream in) throws IOException { StringBuilder stringBuilder = new StringBuilder(); StringBuilder out = new StringBuilder(); int temp = 0; Deque<Character> deque = new LinkedList<>(); HashSet<Character> set = new HashSet<>(); while ((temp = in.read()) != -1) { char c = (char)temp; if (c == '\n') break; stringBuilder.append(c);
    } for (int i = stringBuilder.length()-1; i >=0 ; i--) { if (set.add(stringBuilder.charAt(i))) { deque.add(stringBuilder.charAt(i));
        }
    } while (!deque.isEmpty()) { out.append(deque.pollFirst());
    } return out.toString();
} public static void main(String[] args) throws Exception { InputStream in = System.in; String out = nonRepeated2(in); System.out.println(out); in.close();
}
#提取不重复的整数#
全部评论

相关推荐

qz鹿:*** 祝他毕业就失业
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务