Skip to content

Commit

Permalink
Merge pull request #428 from Shubh-Krishna/main
Browse files Browse the repository at this point in the history
Completed Day18q3 Palindrome Linked list Day19 q1 Find Players with Zeroes and One and Day 19 q3 Letter Combination of a Phone number
  • Loading branch information
bh-g authored Jan 22, 2024
2 parents e7b2f56 + 98646fc commit 7545a2f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Day-18/q3:Palindrome Linked List/Shubh-Krishna--c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
```
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
bool isPalindrome(ListNode* head) {
ListNode *s=head;
int i=0;
while (s != nullptr){
i++;
s=s->next;
}
s = head;
int arr[i];
for (int j=0;j<i;j++){
arr[j]=s->val;
s=s->next;
}
for (int a = 0, b = i - 1; a < b; a++, b--) {
if (arr[a] != arr[b]) {
return false;
}
}
return true;
}
};
```
15 changes: 15 additions & 0 deletions Day-18/q3:Palindrome Linked List/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Palindrome Linked List
Given the head of a singly linked list, return true if it is a
palindrome or false otherwise.

## Example 1:
Input: head = [1,2,2,1]

Output: true


## Example 2:

Input: head = [1,2]

Output: false
18 changes: 18 additions & 0 deletions Day-19/q1 Find Players With Zero or One Losses/Shubh-Krishna--c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```
class Solution {
public:
vector<vector<int>> findWinners(vector<vector<int>>& matches) {
map<int, pair<int, int>> mp;
for(auto i : matches){
mp[i[0]].first++;
mp[i[1]].second++;
}
vector<vector<int>> ans(2);
for(auto [i, v] : mp){
if(v.second == 0) ans[0].push_back(i);
else if(v.second == 1) ans[1].push_back(i);
}
return ans;
}
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```
vector<string> res;
string key[10] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
public:
vector<string> letterCombinations(string digits) {
if(digits.empty()) return res_;
recur(digits, "", 0);
return res;
}
void recur(string s, string cur, int index){
if(index == s.length()) res_.emplace_back(cur);
else{
string letters = key[s[index] - '0'];
for(const char c: letters){
recur(s, cur + c, index + 1);
}
}
}
```

0 comments on commit 7545a2f

Please sign in to comment.