Skip to content

Commit 2c3b464

Browse files
committed
commiting changes 08/14
1 parent b16915b commit 2c3b464

5 files changed

Lines changed: 100 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,25 @@ Feel free to add issues, comment and pull request.
4545
| Leetcode | [387. First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/) | [Java](./java/FirstUniqChar.java) \| [Python](./Python/) | _O(n)_ | _O(n)_ | Easy | |
4646
| Leetcode | [647. Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/) | [Java](./java/CountSubstrings.java) \| [Python](./Python/) | _O(n^2)_ | _O(1)_ | Easy | |
4747
| Leetcode | [500. Keyboard Row](https://leetcode.com/problems/keyboard-row/description/) | [Java](./java/findWords.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
48+
| Leetcode | [293. Flip Game](https://leetcode.com/problems/flip-game/description/ | [Java](./java/generatePossibleNextMoves.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
4849

4950
## HashMap
5051
| Website | Title | Solution | Time | Space | Difficulty | Note|
5152
|---------------- |---------------- | ----------- | --------------- | --------------- | ------------- |-----|
5253
| Leetcode | [1. Two Sum](https://leetcode.com/problems/two-sum) | [Java](./java/Twosum.java) \| [Python](./Python/) | _O(n)_ | _O(n)_ | Easy | |
54+
| Leetcode | [359. Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter/description/) | [Java](./java/shouldPrintMessage.java) \| [Python](./Python/) | _O(n)_ | _O(n)_ | Easy | |
55+
| Leetcode | [535. Encode and Decode TinyURL](https://leetcode.com/problems/encode-and-decode-tinyurl/description/) | [Java](./java/Codec.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Medium | |
56+
| Leetcode | [266. Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation/description/) | [Java](./java/canPermutePalindrome.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
57+
58+
5359

5460
## Trees
5561
| Website | Title | Solution | Time | Space | Difficulty | Note|
5662
|---------------- |---------------- | ----------- | --------------- | --------------- | ------------- |-----|
5763
| Leetcode | [653. Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst/description/) | [Java](./java/Twosum.java) \| [Python](./Python/) | _O(n)_ | _O(n)_ | Easy | |
5864
| Leetcode | [617. Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees/description/) | [Java](./java/mergeTrees.java) \| [Python](./Python/) | _O(mn)_ | _O(1)_ | Easy | |
65+
| Leetcode | [637. Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree/description/) | [Java](./java/averageOfLevels.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
66+
5967

6068
## Dynamic Programming
6169
| Website | Title | Solution | Time | Space | Difficulty | Note|

java/Codec.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class Codec {
2+
3+
private Map<Integer, String> map = new HashMap<>();
4+
private String host = "http://tinyurl.com/";
5+
6+
// Encodes a URL to a shortened URL.
7+
public String encode(String longUrl) {
8+
int hashKey = longUrl.hashCode();
9+
map.put(hashKey, longUrl);
10+
return host+hashKey;
11+
12+
}
13+
14+
// Decodes a shortened URL to its original URL.
15+
public String decode(String shortUrl) {
16+
17+
int hashKey = Integer.parseInt(shortUrl.replace(host,""));
18+
return map.get(hashKey);
19+
20+
}
21+
}
22+
23+
// Your Codec object will be instantiated and called as such:
24+
// Codec codec = new Codec();
25+
// codec.decode(codec.encode(url));

java/averageOfLevels.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode(int x) { val = x; }
8+
* }
9+
*/
10+
public class Solution {
11+
public List<Double> averageOfLevels(TreeNode root) {
12+
List<Double> list = new ArrayList<>();
13+
Queue<TreeNode> queue = new LinkedList<>();
14+
15+
if(root == null)
16+
return list;
17+
queue.add(root);
18+
19+
while(!queue.isEmpty())
20+
{
21+
int queueSize = queue.size();
22+
double sum = 0.0;
23+
24+
for(int i=0; i<queueSize; i++)
25+
{
26+
TreeNode node = queue.poll();
27+
sum += node.val;
28+
if(node.left != null)
29+
queue.offer(node.left);
30+
if(node.right != null)
31+
queue.offer(node.right);
32+
}
33+
list.add(sum/queueSize);
34+
}
35+
return list;
36+
37+
}
38+
}

java/canPermutePalindrome.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Solution {
2+
public boolean canPermutePalindrome(String s) {
3+
HashSet<Character> set = new HashSet<>();
4+
5+
for(int i=0; i<s.length(); i++)
6+
{
7+
if(!set.contains(s.charAt(i)))
8+
set.add(s.charAt(i));
9+
else
10+
set.remove(s.charAt(i));
11+
}
12+
13+
return set.size()==0 || set.size()==1;
14+
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Solution {
2+
public List<String> generatePossibleNextMoves(String s) {
3+
List<String> result = new ArrayList<>();
4+
5+
for(int i=1; i<s.length(); i++)
6+
{
7+
if(s.charAt(i-1) == '+' && s.charAt(i)=='+')
8+
result.add(s.substring(0,i-1) + "--" + s.substring(i+1,s.length()));
9+
}
10+
11+
return result;
12+
}
13+
}

0 commit comments

Comments
 (0)