diff --git a/Decimal To Binary.py b/Decimal To Binary.py index 53ea7a8..8c3e993 100644 --- a/Decimal To Binary.py +++ b/Decimal To Binary.py @@ -1,18 +1,2 @@ -def decToBinary(n): - - # array to store - # binary number - binaryNum = [0] * n; - - # counter for binary array - i = 0; - while (n > 0): - - # storing remainder - binaryNum[i] = n % 2; - n = int(n / 2); - i += 1; - - # printing binary array - for j in range(i - 1, -1, -1): - print(binaryNum[j], end = ""); +def decimalToBinary(n): + print(bin(n).replace("0b","")) \ No newline at end of file diff --git a/LowestCommenSubsequence.py b/LowestCommenSubsequence.py index e3fced4..17493d0 100644 --- a/LowestCommenSubsequence.py +++ b/LowestCommenSubsequence.py @@ -1,20 +1,12 @@ def lcs(X, Y): - # find the length of the strings m = len(X) - n = len(Y) - - # declaring the array for storing the dp values - L = [[None]*(n - 1) for i in range(m - 1)] - - for i in range(m + 1): - for j in range(n + 1): - if i == 0 or j == 0 : - L[i][j] = 0 - elif X[i-1] == Y[j-1]: - L[i][j] = L[i-1][j-1]+1 - else: - L[i][j] = max(L[i-1][j], L[i][j-1]) - return L[m][n] + n = len(Y) + if m == 0 or n == 0: + return 0; + elif X[m-1] == Y[n-1]: + return 1 + lcs(X, Y, m-1, n-1); + else: + return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n)); X = "AGGTAB" Y = "GXTXAYB" print("Length of LCS is ", lcs(X, Y))