Skip to content
Go back

2591-distribute-money-to-maximum-children

2591 https://leetcode.cn/problems/distribute-money-to-maximum-children/

struct Solution {}

impl Solution {
  pub fn dist_money(money: i32, children: i32) -> i32 {
    if money < children {
      return -1;
    }
    let mut cnt = (money - children) / 7;
    let m = (money - children) % 7;
    if cnt >= children {
      if m > 0 || cnt > children {
        return children - 1;
      }
      return children;
    }
    if cnt > 0 && cnt == children - 1 && m == 3 {
      cnt -= 1;
    }
    if cnt < 0 {
      return -1;
    }
    cnt
  }
}

Share this post on:

Previous Post
1638-count-substrings-that-differ-by-one-character
Next Post
2529-maximum-count-of-positive-integer-and-negative-integer