Skip to content

Commit d1c73b0

Browse files
Merge pull request codemistic#582 from abhishekdey4444/main
1614. Maximum Nesting Depth of the Parentheses
2 parents 61e1592 + 3a6847b commit d1c73b0

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public int maxDepth(String s) {
3+
Stack<Character> st=new Stack<>();
4+
int count=0;
5+
for(int i=0;i<s.length();i++){
6+
if(s.charAt(i)=='('){
7+
st.push(s.charAt(i));
8+
}
9+
else{
10+
if(count<st.size())
11+
count=st.size();
12+
13+
else if(s.charAt(i)==')'){
14+
st.pop();
15+
}
16+
17+
}
18+
19+
}
20+
return count;
21+
}
22+
}

Java/Leetcode/198. House Robber

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public static int max(int []arr,int idx,int []dp){
3+
if(idx>=arr.length){
4+
return 0;
5+
}
6+
if(dp[idx]!=-1){
7+
return dp[idx];
8+
}
9+
int a=arr[idx]+max(arr,idx+2,dp);
10+
int b=max(arr,idx+1,dp);
11+
12+
return dp[idx]=Math.max(a,b);
13+
}
14+
public int rob(int[] nums) {
15+
int []dp=new int[nums.length];
16+
for(int i=0;i<nums.length;i++){
17+
dp[i]=-1;
18+
}
19+
return max(nums,0,dp);
20+
}
21+
}

0 commit comments

Comments
 (0)