LeetCode 第 153 场周赛

一、公交站间的距离(LeetCode-5181)

1.1 题目描述

789766-20190909002241333-739159960.png

1.2 解题思路

比较简单的一题,顺时针、逆时针两次遍历,就能解决。

1.3 解题代码

class Solution {
    public int distanceBetweenBusStops(int[] distance, int start, int destination) {
        int res = 0;
        int len = distance.length;

        int i = start;
        do {
            res += distance[i];
            i++;
            if (i > len - 1) {
                i = 0;
            }
        } while (i != destination);


        int tmp = 0;
        int j = destination;
        do {
            tmp += distance[j];
            j++;
            if (j > len - 1) {
                j = 0;
            }
        } while (j != start && j != destination);


        return res < tmp ? res : tmp;
    }
}

二、 一周中的第几天(LeetCode-5183)

2.1 题目描述

789766-20190909002441444-1638316451.png

2.2 解题思路

调用工具类水过。。。。

2.3 解题代码

import java.util.Calendar;
class Solution {
    public String dayOfTheWeek(int day, int month, int year) {
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, day);
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        switch (dayOfWeek) {
            case 1:
                return "Sunday";
            case 2:
                return "Monday";
            case 3:
                return "Tuesday";
            case 4:
                return "Wednesday";
            case 5:
                return "Thursday";
            case 6:
                return "Friday";
            case 7:
                return "Saturday";
        }
        return "";
    }
}

转载于:https://www.cnblogs.com/fonxian/p/11489396.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值