File tree 3 files changed +32
-2
lines changed
3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 132
132
| 492 | [ Construct the Rectangle] ( https://leetcode.com/problems/construct-the-rectangle ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ConstructTheRectangle.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/construct_the_rectangle.py ) |
133
133
| 496 | [ Next Greater Element I] ( https://leetcode.com/problems/next-greater-element-i ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/NextGreaterElementI.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/next_greater_element_i.py ) |
134
134
| 500 | [ Keyboard Row] ( https://leetcode.com/problems/keyboard-row ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/KeyBoardRow.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/keyboard_row.py ) |
135
- | 501 | [ Find Mode in Binary Search Tree] ( https://leetcode.com/problems/find-mode-in-binary-search-tree ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/FindModeInBinarySearchTree ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/find_mode_in_binary_search_tree.py ) |
136
- | 504 | [ Base 7] ( https://leetcode.com/problems/base-7 ) | Easy | |
135
+ | 501 | [ Find Mode in Binary Search Tree] ( https://leetcode.com/problems/find-mode-in-binary-search-tree ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/FindModeInBinarySearchTree.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/find_mode_in_binary_search_tree.py ) |
136
+ | 504 | [ Base 7] ( https://leetcode.com/problems/base-7 ) | Easy | [ ![ Java ] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/Base7.java ) [ ![ Python ] ( https://img.icons8.com/color/35/000000/python.png )] ( python/base_7.py ) |
137
137
| 506 | [ Relative Ranks] ( https://leetcode.com/problems/relative-ranks ) | Easy | |
138
138
| 507 | [ Perfect Number] ( https://leetcode.com/problems/perfect-number ) | Easy | |
139
139
| 509 | [ Fibonacci Number] ( https://leetcode.com/problems/fibonacci-number ) | Easy | |
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def convertToBase7 (self , num : int ) -> str :
3
+ if num == 0 :
4
+ return '0'
5
+ is_negative = num < 0
6
+ num = - num if is_negative else num
7
+ result = ''
8
+ while num > 0 :
9
+ result = str (num % 7 ) + result
10
+ num //= 7
11
+ return ('-' if is_negative else '' ) + result
Original file line number Diff line number Diff line change
1
+ public class Base7 {
2
+ public static String convertToBase7 (int number ) {
3
+ if (number == 0 ) return "0" ;
4
+ StringBuilder result = new StringBuilder ();
5
+ boolean isNegative = number < 0 ;
6
+ if (isNegative ) {
7
+ number *= -1 ;
8
+ }
9
+ while (number > 0 ) {
10
+ result .append (number % 7 );
11
+ number /= 7 ;
12
+ }
13
+ return result .append (isNegative ? "-" : "" ).reverse ().toString ();
14
+ }
15
+
16
+ public static void main (String [] args ) {
17
+ System .out .println (convertToBase7 (-7 ));
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments