From 5840007f667ec0ebe40609b61096f799a29f3f0b Mon Sep 17 00:00:00 2001 From: Shubh Krishna <135266175+Shubh-Krishna@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:43:10 +0530 Subject: [PATCH 01/11] Create solution.cpp --- Day-19/q3-Letter Combinations of a Phone Number/solution.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 Day-19/q3-Letter Combinations of a Phone Number/solution.cpp diff --git a/Day-19/q3-Letter Combinations of a Phone Number/solution.cpp b/Day-19/q3-Letter Combinations of a Phone Number/solution.cpp new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Day-19/q3-Letter Combinations of a Phone Number/solution.cpp @@ -0,0 +1 @@ + From 63150fbb6e3546dfc7208489c5e3b4ea3b6b9b6e Mon Sep 17 00:00:00 2001 From: Shubh Krishna <135266175+Shubh-Krishna@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:44:43 +0530 Subject: [PATCH 02/11] Update solution.cpp --- .../solution.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Day-19/q3-Letter Combinations of a Phone Number/solution.cpp b/Day-19/q3-Letter Combinations of a Phone Number/solution.cpp index 8b137891..f7e819b7 100644 --- a/Day-19/q3-Letter Combinations of a Phone Number/solution.cpp +++ b/Day-19/q3-Letter Combinations of a Phone Number/solution.cpp @@ -1 +1,19 @@ + vector res; + string key[10] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; + public: + vector 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); + } + } + } + From 24cd26df69b0a1710a36d038ae9051e4770ef839 Mon Sep 17 00:00:00 2001 From: Shubh Krishna <135266175+Shubh-Krishna@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:49:48 +0530 Subject: [PATCH 03/11] Create question.md --- Day-18/q3:Palindrome Linked List/question.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Day-18/q3:Palindrome Linked List/question.md diff --git a/Day-18/q3:Palindrome Linked List/question.md b/Day-18/q3:Palindrome Linked List/question.md new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Day-18/q3:Palindrome Linked List/question.md @@ -0,0 +1 @@ + From 05fce6942a8f488693fb48589d33359cfa14cdc8 Mon Sep 17 00:00:00 2001 From: Shubh Krishna <135266175+Shubh-Krishna@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:51:11 +0530 Subject: [PATCH 04/11] Update question.md --- Day-18/q3:Palindrome Linked List/question.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Day-18/q3:Palindrome Linked List/question.md b/Day-18/q3:Palindrome Linked List/question.md index 8b137891..ec27792e 100644 --- a/Day-18/q3:Palindrome Linked List/question.md +++ b/Day-18/q3:Palindrome Linked List/question.md @@ -1 +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 From 1c7cd14f7c9c2b76491616c997189b16753208d0 Mon Sep 17 00:00:00 2001 From: Shubh Krishna <135266175+Shubh-Krishna@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:51:35 +0530 Subject: [PATCH 05/11] Create solution.cpp --- Day-18/q3:Palindrome Linked List/solution.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 Day-18/q3:Palindrome Linked List/solution.cpp diff --git a/Day-18/q3:Palindrome Linked List/solution.cpp b/Day-18/q3:Palindrome Linked List/solution.cpp new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Day-18/q3:Palindrome Linked List/solution.cpp @@ -0,0 +1 @@ + From f34d5d42ba57aa524166a2a1fd933fb1c58e3baf Mon Sep 17 00:00:00 2001 From: Shubh Krishna <135266175+Shubh-Krishna@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:52:05 +0530 Subject: [PATCH 06/11] Update solution.cpp --- Day-18/q3:Palindrome Linked List/solution.cpp | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Day-18/q3:Palindrome Linked List/solution.cpp b/Day-18/q3:Palindrome Linked List/solution.cpp index 8b137891..bc48ab83 100644 --- a/Day-18/q3:Palindrome Linked List/solution.cpp +++ b/Day-18/q3:Palindrome Linked List/solution.cpp @@ -1 +1,45 @@ +/** + * 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;jval; + s=s->next; + } + for (int a = 0, b = i - 1; a < b; a++, b--) { + if (arr[a] != arr[b]) { + return false; + } + } + return true; + } +}; + + + + + + + + + + + From 9bf3ad9b9620b6dfceccf44a651d965fadfdb223 Mon Sep 17 00:00:00 2001 From: Shubh Krishna <135266175+Shubh-Krishna@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:04:50 +0530 Subject: [PATCH 07/11] Create solution.cpp --- Day-19/q1 Find Players With Zero or One Losses/solution.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 Day-19/q1 Find Players With Zero or One Losses/solution.cpp diff --git a/Day-19/q1 Find Players With Zero or One Losses/solution.cpp b/Day-19/q1 Find Players With Zero or One Losses/solution.cpp new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Day-19/q1 Find Players With Zero or One Losses/solution.cpp @@ -0,0 +1 @@ + From 14bb06d5703a7ba316c2607dde032a5e0afe12bd Mon Sep 17 00:00:00 2001 From: Shubh Krishna <135266175+Shubh-Krishna@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:05:07 +0530 Subject: [PATCH 08/11] Update solution.cpp --- .../solution.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Day-19/q1 Find Players With Zero or One Losses/solution.cpp b/Day-19/q1 Find Players With Zero or One Losses/solution.cpp index 8b137891..e858418a 100644 --- a/Day-19/q1 Find Players With Zero or One Losses/solution.cpp +++ b/Day-19/q1 Find Players With Zero or One Losses/solution.cpp @@ -1 +1,16 @@ - +class Solution { +public: + vector> findWinners(vector>& matches) { + map> mp; + for(auto i : matches){ + mp[i[0]].first++; + mp[i[1]].second++; + } + vector> 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; + } +}; From 7b95fd2c0dfcf9f7806d3fb0c28189379c00c62c Mon Sep 17 00:00:00 2001 From: Bhumika Gupta <95757762+bh-g@users.noreply.github.com> Date: Tue, 23 Jan 2024 02:33:38 +0530 Subject: [PATCH 09/11] Update and rename solution.cpp to Shubh-Krishna--c.md --- .../{solution.cpp => Shubh-Krishna--c.md} | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) rename Day-18/q3:Palindrome Linked List/{solution.cpp => Shubh-Krishna--c.md} (98%) diff --git a/Day-18/q3:Palindrome Linked List/solution.cpp b/Day-18/q3:Palindrome Linked List/Shubh-Krishna--c.md similarity index 98% rename from Day-18/q3:Palindrome Linked List/solution.cpp rename to Day-18/q3:Palindrome Linked List/Shubh-Krishna--c.md index bc48ab83..219c6bd9 100644 --- a/Day-18/q3:Palindrome Linked List/solution.cpp +++ b/Day-18/q3:Palindrome Linked List/Shubh-Krishna--c.md @@ -1,4 +1,4 @@ - +``` /** * Definition for singly-linked list. * struct ListNode { @@ -32,14 +32,4 @@ class Solution { return true; } }; - - - - - - - - - - - +``` From 0752a46eaa487e02991a007c53b993bb58326d6f Mon Sep 17 00:00:00 2001 From: Bhumika Gupta <95757762+bh-g@users.noreply.github.com> Date: Tue, 23 Jan 2024 02:34:25 +0530 Subject: [PATCH 10/11] Update and rename solution.cpp to Shubh-Krishna--c.md --- .../{solution.cpp => Shubh-Krishna--c.md} | 2 ++ 1 file changed, 2 insertions(+) rename Day-19/q1 Find Players With Zero or One Losses/{solution.cpp => Shubh-Krishna--c.md} (98%) diff --git a/Day-19/q1 Find Players With Zero or One Losses/solution.cpp b/Day-19/q1 Find Players With Zero or One Losses/Shubh-Krishna--c.md similarity index 98% rename from Day-19/q1 Find Players With Zero or One Losses/solution.cpp rename to Day-19/q1 Find Players With Zero or One Losses/Shubh-Krishna--c.md index e858418a..1280976f 100644 --- a/Day-19/q1 Find Players With Zero or One Losses/solution.cpp +++ b/Day-19/q1 Find Players With Zero or One Losses/Shubh-Krishna--c.md @@ -1,3 +1,4 @@ +``` class Solution { public: vector> findWinners(vector>& matches) { @@ -14,3 +15,4 @@ class Solution { return ans; } }; +``` From 98646fc141a27b32f2941d67ecb96046b9722a72 Mon Sep 17 00:00:00 2001 From: Bhumika Gupta <95757762+bh-g@users.noreply.github.com> Date: Tue, 23 Jan 2024 02:34:48 +0530 Subject: [PATCH 11/11] Update and rename solution.cpp to Shubh-Krishna--c.md --- .../{solution.cpp => Shubh-Krishna--c.md} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename Day-19/q3-Letter Combinations of a Phone Number/{solution.cpp => Shubh-Krishna--c.md} (98%) diff --git a/Day-19/q3-Letter Combinations of a Phone Number/solution.cpp b/Day-19/q3-Letter Combinations of a Phone Number/Shubh-Krishna--c.md similarity index 98% rename from Day-19/q3-Letter Combinations of a Phone Number/solution.cpp rename to Day-19/q3-Letter Combinations of a Phone Number/Shubh-Krishna--c.md index f7e819b7..a479b228 100644 --- a/Day-19/q3-Letter Combinations of a Phone Number/solution.cpp +++ b/Day-19/q3-Letter Combinations of a Phone Number/Shubh-Krishna--c.md @@ -1,4 +1,4 @@ - +``` vector res; string key[10] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; public: @@ -16,4 +16,4 @@ } } } - +```