Skip to content

HJ9 提取不重复的整数 #9

@sumulige

Description

@sumulige
  • 输入一个 int 型整数,按照从右向左的阅读顺序,返回一个不含重复数字的新的整数。
    保证输入的整数最后一位不是 0 。

  • 数据范围:

  • 递归遍历+问题分解+分类讨论

    • 采用Linkedhashset
    • 倒叙
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int input = in.nextInt();

            Set<Integer> linkedHashSet = new LinkedHashSet<>(Collections.singletonList(
                        input));

            for (int i = linkedHashSet.size(); i > 0; i --) {
                System.out.println(i +  " ");
            }

        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions