Advertisement
codeinpublic

https://binarysearch.com/problems/Collatz-Sequence solution

May 27th, 2022
681
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution:
  2.     def solve(self, n):
  3.         count = 1
  4.  
  5.         while n != 1:
  6.             if n % 2:
  7.                 n = 3 * n + 1
  8.             else:
  9.                 n = n / 2
  10.  
  11.             count += 1
  12.  
  13.         return count
  14.  
Advertisement
RAW Paste Data Copied
Advertisement