class Solution {
public:
int addDigits(int num) {
while(num>=10)
{
int temp=0;
while(num)
{
temp+=num%10;
num/=10;
}
num=temp;
}
return num;
}
};
LeetCode:258. 各位相加
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
LeetCode_圆圈中最后剩下的数字_Math_E
面試題62. 圓圈中最後剩下的數字 class Solution { public int lastRemaining(int n, int m) { // 模擬法 List<Integer> l
LeetCode_两数之和_Array_E
1. 兩數之和 暴力: class Solution { public int[] twoSum(int[] nums, int target) { int[] res = new int[2];
LeetCode_旋转矩阵_Array_M
01.07. 旋轉矩陣 簡單粗暴: class Solution { public void rotate(int[][] matrix) { int size = matrix.length;
LeetCode_盛最多水的容器_Array_M
11. 盛最多水的容器 暴力... class Solution { public int maxArea(int[] height) { int max = 0; for (int i
LeetCode_整数反转_Math_E
7. 整數反轉 class Solution { public int reverse(int x) { long result = 0; while (x != 0) { // 如果是-1
LeetCode_实现 Trie (前缀树)_Trie_M
208. 實現 Trie (前綴樹) class Trie { //定義節點 class TrieNode { boolean isEnd; TrieNode[] next = new
LeetCode_排序数组_Array_M
912. 排序數組 class Solution { public int[] sortArray(int[] nums) { quickSort(nums, 0, nums.length - 1);