Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8f0d05

Browse files
authored
Sri Hari: Batch-8/Added-articles (#4299)
* Batch-7/Neetcode-ALL/Added-articles* Batch-7/Neetcode-ALL/Added-articles* Batch-7/Neetcode-ALL/Added-articles* Batch-7/Neetcode-ALL/Added-articles* Batch-7/Neetcode-ALL/Added-articles* Batch-7/Neetcode-ALL/Added-articles* Batch-7/Neetcode-ALL/Added-articles* Batch-7/Neetcode-ALL/Added-articles* Batch-8/Neetcode-ALL/Added-articles* Batch-8/Neetcode-ALL/Added-articles* Batch-8/Neetcode-ALL/Added-articles* Batch-8/Neetcode-ALL/Added-articles
1 parent3d2b2c0 commitd8f0d05

File tree

55 files changed

+9098
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+9098
-49
lines changed

‎articles/add-binary.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,39 @@ class Solution {
114114
}
115115
```
116116

117+
```csharp
118+
publicclassSolution {
119+
publicstringAddBinary(stringa,stringb) {
120+
StringBuilderres=newStringBuilder();
121+
intcarry=0;
122+
123+
char[]sa=a.ToCharArray();
124+
char[]sb=b.ToCharArray();
125+
Array.Reverse(sa);
126+
Array.Reverse(sb);
127+
128+
intn=Math.Max(sa.Length,sb.Length);
129+
130+
for (inti=0;i<n;i++) {
131+
intdigitA=i<sa.Length?sa[i]-'0':0;
132+
intdigitB=i<sb.Length?sb[i]-'0':0;
133+
134+
inttotal=digitA+digitB+carry;
135+
res.Append((char)((total%2)+'0'));
136+
carry=total/2;
137+
}
138+
139+
if (carry>0) {
140+
res.Append('1');
141+
}
142+
143+
char[]resultArray=res.ToString().ToCharArray();
144+
Array.Reverse(resultArray);
145+
returnnewstring(resultArray);
146+
}
147+
}
148+
```
149+
117150
::tabs-end
118151

119152
###Time & Space Complexity
@@ -230,6 +263,32 @@ class Solution {
230263
}
231264
```
232265

266+
```csharp
267+
publicclassSolution {
268+
publicstringAddBinary(stringa,stringb) {
269+
StringBuilderres=newStringBuilder();
270+
intcarry=0;
271+
272+
inti=a.Length-1,j=b.Length-1;
273+
while (i>=0||j>=0||carry>0) {
274+
intdigitA=i>=0?a[i]-'0':0;
275+
intdigitB=j>=0?b[j]-'0':0;
276+
277+
inttotal=digitA+digitB+carry;
278+
res.Append(total%2);
279+
carry=total/2;
280+
281+
i--;
282+
j--;
283+
}
284+
285+
char[]resultArray=res.ToString().ToCharArray();
286+
Array.Reverse(resultArray);
287+
returnnewstring(resultArray);
288+
}
289+
}
290+
```
291+
233292
::tabs-end
234293

235294
###Time & Space Complexity

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp