java.lang.Object
g0801_0900.s0829_consecutive_numbers_sum.Solution

public class Solution extends Object
829 - Consecutive Numbers Sum.<p>Hard</p> <p>Given an integer <code>n</code>, return <em>the number of ways you can write</em> <code>n</code> <em>as the sum of consecutive positive integers.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 5</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> 5 = 2 + 3</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 9</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> 9 = 4 + 5 = 2 + 3 + 4</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 15</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • consecutiveNumbersSum

      public int consecutiveNumbersSum(int n)