TreeviewCopyright © aleen42 all right reserved, powered by aleen42

258. 各位相加

https://leetcode-cn.com/problems/add-digits/

Java

/*
 * @Author: Goog Tech
 * @Date: 2020-08-16 14:24:10
 * @LastEditTime: 2020-08-16 14:25:49
 * @Description: https://leetcode-cn.com/problems/add-digits/
 * @FilePath: \leetcode-googtech\#258. Add Digits\Solution.java
 * @WebSite: https://algorithm.show/
 */

class Solution {
    public int addDigits(int num) {
        if(num < 10) return num;
        return num % 9 == 0 ? 9 : num % 9;
    }
}

Python

'''
Author: Goog Tech
Date: 2020-08-16 14:25:08
LastEditTime: 2020-08-16 14:25:22
Description: https://leetcode-cn.com/problems/add-digits/
FilePath: \leetcode-googtech\#258. Add Digits\Solution.py
WebSite: https://algorithm.show/
'''

class Solution(object):
    def addDigits(self, num):
        """
        :type num: int
        :rtype: int
        """
        if num < 10: return num
        return 9 if num % 9 == 0 else num % 9
Copyright © GoogTech 2021 all right reserved,powered by GitbookLast update time : 2021-09-15 01:55:05

results matching ""

    No results matching ""