My Fifteenth Page - 快乐数 - By Nicolas

本文介绍了一种解决LeetCode上202题的算法,即判断一个正整数是否为快乐数。快乐数是指通过将每位数字平方求和,重复此过程,最终若结果回到1,则该数为快乐数。代码中使用了HashSet存储中间结果,避免重复,并通过循环判断是否达到条件。

今天小尼写的这篇page针对的是leetcode上的202.快乐数所写的,首先小尼先简单介绍一下这道题,就是给定一正整数,然后每一次将该数的每一位都平方再相加得到一个新的数据,我们不断的反腐操作,最后如果这个数经过多次操作后返回到了原来的这个数,那么我们称这个数为快乐数。

小尼先拉一下代码:

public int A(int n) {
    int num = 0;
    while (n > 0) {
        int a = n % 10;
        num += a * a;
        n = n / 10;
    }
    return num;
}
public boolean isHappy(int n){
    Set<Integer> set = new HashSet<>();
    while(n != 1 && !set.contains(n)){
        set.add(n);
        n = A(n);
    }
    return n == 1;
}

这里先写了一个对值进行每个数平方再加起来的和的方法,然后再对boolean的方法进行一个新的判断,利用set数据类型进行对应的contains判断,最后如果符合或者不符合返回一个return值

### 3.6 `<cron-picker>` 组件多语言配置问题分析 在 Vue 中使用 `cron-picker-vue` 组件时,多语言配置是通过 `locale` 属性实现的。若配置未生效,通常是因为组件的国际化支持未正确集成或语言包未正确加载。`cron-picker-vue` 的多语言机制依赖于其内部的语言包定义,若未正确配置 `locale` 或未提供对应的翻译内容,则可能导致界面仍以默认语言(如英文)显示。 ### 3.7 常见原因及解决方法 #### 3.7.1 语言包未正确引入 `cron-picker-vue` 默认支持英文,其他语言需要手动引入对应的语言包。如果未正确引入中文或其他语言包,组件将不会切换语言。确保在组件中正确引入语言包并设置 `locale` 属性。 ```javascript import CronPicker from 'cron-picker-vue' import zh from 'cron-picker-vue/src/locales/zh' ``` 在 `data()` 中定义 `cronLocale` 以提供本地化配置: ```javascript computed: { cronLocale () { return { everyText: this.$t('CronPicker.every'), minutesText: this.$t('CronPicker.minutes'), hoursText: this.$t('CronPicker.hours'), daysText: this.$t('CronPicker.days'), weeksText: this.$t('CronPicker.weeks'), monthsText: this.$t('CronPicker.months'), yearsText: this.$t('CronPicker.years'), specificWeekdayText: this.$t('CronPicker.specificWeekday'), specificDateText: this.$t('CronPicker.specificDate'), specificTimeText: this.$t('CronPicker.specificTime'), specificMinuteText: this.$t('CronPicker.specificMinute'), specificHourText: this.$t('CronPicker.specificHour'), specificDayText: this.$t('CronPicker.specificDay'), specificMonthText: this.$t('CronPicker.specificMonth'), specificYearText: this.$t('CronPicker.specificYear'), atText: this.$t('CronPicker.at'), andText: this.$t('CronPicker.and'), onText: this.$t('CronPicker.on'), ofText: this.$t('CronPicker.of'), theText: this.$t('CronPicker.the'), lastText: this.$t('CronPicker.last'), firstText: this.$t('CronPicker.first'), secondText: this.$t('CronPicker.second'), thirdText: this.$t('CronPicker.third'), fourthText: this.$t('CronPicker.fourth'), fifthText: this.$t('CronPicker.fifth'), sixthText: this.$t('CronPicker.sixth'), seventhText: this.$t('CronPicker.seventh'), eighthText: this.$t('CronPicker.eighth'), ninthText: this.$t('CronPicker.ninth'), tenthText: this.$t('CronPicker.tenth'), eleventhText: this.$t('CronPicker.eleventh'), twelfthText: this.$t('CronPicker.twelfth'), thirteenthText: this.$t('CronPicker.thirteenth'), fourteenthText: this.$t('CronPicker.fourteenth'), fifteenthText: this.$t('CronPicker.fifteenth'), sixteenthText: this.$t('CronPicker.sixteenth'), seventeenthText: this.$t('CronPicker.seventeenth'), eighteenthText: this.$t('CronPicker.eighteenth'), nineteenthText: this.$t('CronPicker.nineteenth'), twentiethText: this.$t('CronPicker.twentieth'), twentyFirstText: this.$t('CronPicker.twentyFirst'), twentySecondText: this.$t('CronPicker.twentySecond'), twentyThirdText: this.$t('CronPicker.twentyThird'), twentyFourthText: this.$t('CronPicker.twentyFourth'), twentyFifthText: this.$t('CronPicker.twentyFifth'), twentySixthText: this.$t('CronPicker.twentySixth'), twentySeventhText: this.$t('CronPicker.twentySeventh'), twentyEighthText: this.$t('CronPicker.twentyEighth'), twentyNinthText: this.$t('CronPicker.twentyNinth'), thirtiethText: this.$t('CronPicker.thirtieth'), thirtyFirstText: this.$t('CronPicker.thirtyFirst'), sundayText: this.$t('CronPicker.sunday'), mondayText: this.$t('CronPicker.monday'), tuesdayText: this.$t('CronPicker.tuesday'), wednesdayText: this.$t('CronPicker.wednesday'), thursdayText: this.$t('CronPicker.thursday'), fridayText: this.$t('CronPicker.friday'), saturdayText: this.$t('CronPicker.saturday') } } } ``` #### 3.7.2 `locale` 属性未正确绑定 在模板中,`cron-picker` 需要绑定 `:locale` 属性以应用语言配置。如果未正确绑定或拼写错误,语言设置将不会生效。 ```vue <template> <cron-picker :cron="form.cron" @change="onChange" :locale="cronLocale" /> </template> ``` #### 3.7.3 多语言资源未加载 如果使用 `vue-i18n` 进行国际化管理,需确保对应的翻译资源已加载。若 `CronPicker.*` 相关翻译未在 `i18n` 配置中定义,则组件可能无法正确显示预期语言。 ```json { "CronPicker": { "every": "每", "minutes": "分钟", "hours": "小时", "days": "天", "weeks": "周", "months": "月", "years": "年", "specificWeekday": "特定星期几", "specificDate": "特定日期", "specificTime": "特定时间", "specificMinute": "特定分钟", "specificHour": "特定小时", "specificDay": "特定天", "specificMonth": "特定月", "specificYear": "特定年", "at": "在", "and": "和", "on": "在", "of": "的", "the": "第", "last": "最后", "first": "第一个", "second": "第二个", "third": "第三个", "fourth": "第四个", "fifth": "第五个", "sixth": "第六个", "seventh": "第七个", "eighth": "第八个", "ninth": "第九个", "tenth": "第十个", "eleventh": "第十一", "twelfth": "第十二", "thirteenth": "第十三", "fourteenth": "第十四", "fifteenth": "第十五", "sixteenth": "第十六", "seventeenth": "第十七", "eighteenth": "第十八", "nineteenth": "第十九", "twentieth": "第二十", "twentyFirst": "第二十一", "twentySecond": "第二十二", "twentyThird": "第二十三", "twentyFourth": "第二十四", "twentyFifth": "第二十五", "twentySixth": "第二十六", "twentySeventh": "第二十七", "twentyEighth": "第二十八", "twentyNinth": "第二十九", "thirtieth": "第三十", "thirtyFirst": "第三十一", "sunday": "星期日", "monday": "星期一", "tuesday": "星期二", "wednesday": "星期三", "thursday": "星期四", "friday": "星期五", "saturday": "星期六" } } ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值