Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9e3d07b

Browse files
Merge pull request #149 from vaibhavkardate/master
code added
2 parents 7a3115f + 30d18dd commit 9e3d07b

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

‎Leetcode/.DS_Store

0 Bytes
Binary file not shown.

‎Leetcode/1328. Break a Palindrome .java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
1328. Break a Palindrome
2+
3+
4+
public String breakPalindrome(String s) {
5+
6+
int l=s.length();
7+
if(l==1)
8+
return("");
9+
10+
char ch[]=s.toCharArray();
11+
for(int i=0;i<ch.length/2;i++)
12+
{
13+
14+
if(ch[i]!='a')
15+
{
16+
ch[i]='a';
17+
return(String.valueOf(ch));
18+
}
19+
}
20+
21+
ch[l-1]++;
22+
return(String.valueOf(ch));
23+
24+
25+
}

‎Leetcode/New_Question.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target.
2+
3+
4+
5+
Example 1:
6+
7+
8+
Input: root = [5,3,6,2,4,null,7], k = 9
9+
Output: true
10+
11+
12+
Solution:
13+
if(root==null){
14+
15+
return false;
16+
17+
}
18+
19+
Queue<TreeNode>q = new LinkedList<>();
20+
21+
HashSet<Integer>ss = new HashSet<>();
22+
23+
q.offer(root);
24+
25+
while(!q.isEmpty()){
26+
27+
int sz = q.size();
28+
29+
while(sz-->0){
30+
31+
TreeNode n = q.poll();
32+
33+
int nn = n.val;
34+
35+
if(ss.contains(k-nn)){
36+
37+
return true;
38+
}
39+
40+
ss.add(nn);
41+
42+
if(n.left!=null){
43+
44+
q.offer(n.left);
45+
46+
}
47+
48+
if(n.right!=null){
49+
50+
q.offer(n.right);
51+
}
52+
53+
54+
55+
}
56+
57+
58+
}
59+
60+
return false;
61+
62+
63+
}
64+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /