File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
product-of-array-except-self Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * 시간복잡도: O(n)
3+ * 공간복잡도: O(1)
4+ * */
5+ class Solution {
6+ public int [] productExceptSelf (int [] nums ) {
7+ int n = nums .length ;
8+ int [] answer = new int [n ];
9+
10+ answer [0 ] = 1 ;
11+ for (int i = 1 ; i < n ; i ++) {
12+ answer [i ] = answer [i - 1 ] * nums [i - 1 ];
13+ }
14+
15+ int suffixProduct = 1 ;
16+ for (int i = n - 1 ; i >= 0 ; i --) {
17+ answer [i ] *= suffixProduct ;
18+ suffixProduct *= nums [i ];
19+ }
20+
21+ return answer ;
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * 시간복잡도: O(1)
3+ * 공간복잡도: O(1)
4+ * */
5+ public class Solution {
6+ // you need treat n as an unsigned value
7+ public int reverseBits (int n ) {
8+ int result = 0 ;
9+ for (int i = 0 ; i < 32 ; i ++) {
10+ result <<= 1 ;
11+ result |= (n & 1 );
12+ n >>= 1 ;
13+ }
14+ return result ;
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments