Skip to content

Commit 1523d1c

Browse files
committed
FindDifferenceSln
1 parent 80d2bcb commit 1523d1c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* ==============================================================================
2+
* 功能描述:FindDifferenceSln
3+
* 创 建 者:gz
4+
* 创建日期:2017/5/9 13:23:46
5+
* ==============================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
11+
namespace HashTable.Lib
12+
{
13+
/// <summary>
14+
/// FindDifferenceSln
15+
/// </summary>
16+
public class FindDifferenceSln
17+
{
18+
public char FindTheDifference(string s, string t)
19+
{
20+
int[] hash = new int[123]; //97~122
21+
foreach (var ch in s)
22+
hash[Convert.ToInt32(ch)]++;
23+
foreach (var ch in t)
24+
{
25+
int tmp = Convert.ToInt32(ch);
26+
hash[tmp]--;
27+
if (hash[tmp] < 0)
28+
return ch;
29+
}
30+
return ' ';
31+
}
32+
33+
}
34+
}

0 commit comments

Comments
 (0)