Content-Length: 1130 | pFad | http://github.com/fishercoder1534/Leetcode/pull/107.patch
thub.com
From 8536163e9d41c494f415f3be01b6fc9303e3603c Mon Sep 17 00:00:00 2001
From: MITHILESH
Date: Thu, 1 Oct 2020 12:55:12 +0530
Subject: [PATCH] Create Count and Say.cpp
---
cpp/Count and Say.cpp | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 cpp/Count and Say.cpp
diff --git a/cpp/Count and Say.cpp b/cpp/Count and Say.cpp
new file mode 100644
index 0000000000..2e8c4169d8
--- /dev/null
+++ b/cpp/Count and Say.cpp
@@ -0,0 +1,32 @@
+class Solution {
+public:
+ string countAndSay(int n) {
+ string arr[n+1];
+ arr[0]=to_string(0);
+ arr[1]=to_string(1);
+ for(int i=2;i<=n;i++)
+ {
+ arr[i]=cas(arr[i-1]);
+ }
+ return arr[n];
+
+ }
+
+ string cas(string n)
+ {
+
+ string ans="";
+
+ while(!n.empty())
+ {string p=n.substr(0,1);
+ int cnt=0;int i=0;
+ while(n.substr(i,1)==p)
+ {cnt++;i++;}
+ n.erase(0,cnt);
+ ans+=to_string(cnt)+p;
+ }
+ return ans;
+ }
+
+
+};
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/fishercoder1534/Leetcode/pull/107.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy