Java自定义Main函数输入输出样例参考

您所在的位置:网站首页 自定义输入输出函数 Java自定义Main函数输入输出样例参考

Java自定义Main函数输入输出样例参考

2024-02-29 03:45| 来源: 网络整理| 查看: 265

前言

在LeetCode上刷了很长时间的算法题,但只关注了算法本身,却一直忽略了Main函数中输入输出的定义,就好像没穿衣服的“泥娃娃”,导致多次机试上耽误太长时间去思考Main函数中输入输出样例的书写。痛定思痛,参考LeetCode中PlayGround下给出的Main函数模板,给出以下两种不同输入输出格式的Main函数书写样例。笔者能力有限,忘批评指正~感谢

一、键盘输入不确定长度的整数数组,输出为整数:

以LeetCode121题“买股票的最佳时机”为例: 输入输出: 在这里插入图片描述 类说明:

class Solution { public int maxProfit(int[] prices) { } }

Main函数样例:

public class MainClass { public static int[] stringToIntegerArray(String input) { input = input.trim(); input = input.substring(1, input.length() - 1); if (input.length() == 0) { return new int[0]; } String[] parts = input.split(","); int[] output = new int[parts.length]; for(int index = 0; index


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3