Solved 115 tasks in sections algorithm at Leetcode. Solutions to the tasks in this repository.

My solution to reverse-bits.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package by.degree.leetcode.numbers;

/**
 * https://leetcode.com/problems/reverse-bits/
 */
public class ReverseBits
{
	// you need treat n as an unsigned value
	public int reverseBits(int n)
	{
		int cycle = 32;
		int result = 0;
		while (cycle-- > 0)
		{
			result = (result << 1) | (n & 1);
			n >>= 1;
		}
		return result;
	}
}