Removed the class, and made it just one line.
def MaxDigit(n): return int(''.join(sorted(str(n), reverse=True)))
class MaxDigit:def __init__(s, n):s.n = ndef execute(s): return int(''.join(sorted(str(s.n), reverse=True)))- def MaxDigit(n): return int(''.join(sorted(str(n), reverse=True)))
import codewars_test as test # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): samples = [(12, 21), (677, 776), (101, 110), (400000005000007000, 754000000000000000), (307778062924466824,988777666444322200)] for n, e in samples: test.assert_equals(MaxDigit(n), e)
- import codewars_test as test
from solution import MaxDigit- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- samples = [(12, 21), (677, 776), (101, 110), (400000005000007000, 754000000000000000), (307778062924466824,988777666444322200)]
for s, e in samples:test.assert_equals(MaxDigit(s).execute(), e)- for n, e in samples:
- test.assert_equals(MaxDigit(n), e)
Just made it shorter.
public class ReverseString { public static String reverseString(String word) { return new StringBuilder(word).reverse().toString(); } }
- public class ReverseString {
- public static String reverseString(String word) {
StringBuilder result = new StringBuilder(word);return result.reverse().toString();- return new StringBuilder(word).reverse().toString();
- }
- }