From 9f47c6e8888fa3ceb47ea9497ea5b207410bcc5c Mon Sep 17 00:00:00 2001 From: Ritikraja07 Date: Fri, 14 Oct 2022 19:37:51 +0530 Subject: [PATCH 1/2] My first contibution to your program --- cpp/first.cpp | 14 ++++++++++++++ java/70-climbing-stairs.java | 32 ++++++++++++++++---------------- 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 cpp/first.cpp diff --git a/cpp/first.cpp b/cpp/first.cpp new file mode 100644 index 0000000..fc02b0b --- /dev/null +++ b/cpp/first.cpp @@ -0,0 +1,14 @@ +// C++ program to display "Hello World" + +// Header file for input output functions +#include +using namespace std; + +// Main() function: where the execution of program begins +int main() +{ + // prints hello world + cout << "Hello World"; + + return 0; +} diff --git a/java/70-climbing-stairs.java b/java/70-climbing-stairs.java index 9c3470f..12159a4 100644 --- a/java/70-climbing-stairs.java +++ b/java/70-climbing-stairs.java @@ -1,17 +1,17 @@ -class Solution { - public int climbStairs(int n) { - - int dp[] = new int[n+1]; - dp[n] = 1; - for(int i = n; i>=0; i--){ - if(i+1<=n){ - dp[i] = dp[i+1]; - } - if(i+2<=n){ - dp[i] = dp[i+1] + dp[i+2]; - } - } - - return dp[0]; - } +class Solution { + public int climbStairs(int n) { + + int dp[] = new int[n+1]; + dp[n] = 1; + for(int i = n; i>=0; i--){ + if(i+1<=n){ + dp[i] = dp[i+1]; + } + if(i+2<=n){ + dp[i] = dp[i+1] + dp[i+2]; + } + } + + return dp[0]; + } } \ No newline at end of file From f9e948165dc902154721e332acb29becaddd8d44 Mon Sep 17 00:00:00 2001 From: Ritikraja07 Date: Fri, 14 Oct 2022 19:42:16 +0530 Subject: [PATCH 2/2] My contribution to your project --- python/romantointger.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 python/romantointger.py diff --git a/python/romantointger.py b/python/romantointger.py new file mode 100644 index 0000000..ed3025d --- /dev/null +++ b/python/romantointger.py @@ -0,0 +1,34 @@ +class Solution(object): + def romanToInt(self, s): + """ + :type s: str + :rtype: int + """ + roman_dic = { + "I": 1, + "V": 5, + "X": 10, + "L": 50, + "C": 100, + "D": 500, + "M": 1000, + } + + + skip_next_n = False + int_sum = 0 + for idx, n in enumerate(s): + if skip_next_n == True: + skip_next_n = False + continue + try: + if roman_dic[n] < roman_dic[s[idx + 1]]: + int_sum += roman_dic[s[idx + 1]] - roman_dic[n] + skip_next_n = True + continue + else: + int_sum += roman_dic[n] + except: + int_sum += roman_dic[n] + + return int_sum \ No newline at end of file