-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from Shubh-Krishna/main
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
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
Day-19/q1 Find Players With Zero or One Losses/Shubh-Krishna--c.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; | ||
``` |
19 changes: 19 additions & 0 deletions
19
Day-19/q3-Letter Combinations of a Phone Number/Shubh-Krishna--c.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
``` |