leetcode166】的更多相关文章

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. Example 1: Input: numerator = 1, denominator = 2 Output…
public class Solution { public String fractionToDecimal(int numerator, int denominator) { HashMap<Long,Integer> maps = new HashMap<>();//store divid number List<Long> number = new ArrayList<>(); int index = 0; int beginIndex = -1;…
思路: 模拟. 实现: class Solution { public: string fractionToDecimal(int numerator, int denominator) { long long a = numerator, b = denominator; string ans = ""; ) ans += '-'; a = abs(a); b = abs(b); ans += to_string(a / b); a %= b; if (!a) return ans;…
题目描述: 方法一:暴力BFS class Solution: def minFlips(self, mat) -> int: R, C = len(mat), len(mat[0]) def helper(mat): return tuple(tuple(row) for row in mat) visited = set() queue = collections.deque() mat_ = helper(mat) visited.add(mat_) queue.append(mat) a…
题目描述: 自己的提交: class Solution: def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: ans = [] dic = {} for v,i in enumerate(groupSizes): if i in dic: dic[i].append(v) if len(dic[i]) == i: ans.append(dic[i]) dic.pop(i) else: dic[i] = [v] i…
给定两个整数,分别表示分数的分子 numerator 和分母 denominator,以字符串形式返回小数. 如果小数部分为循环小数,则将循环的部分括在括号内. 示例 1: 输入: numerator = 1, denominator = 2 输出: "0.5" 示例 2: 输入: numerator = 2, denominator = 1 输出: "2" 示例 3: 输入: numerator = 2, denominator = 3 输出: "0.(…