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

[pull] master from youngyangyang04:master #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 9 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions problems/0001.两数之和.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,24 @@ class Solution {
}
}
```
C#:
```csharp
public class Solution {
public int[] TwoSum(int[] nums, int target) {
Dictionary<int ,int> dic= new Dictionary<int,int>();
for(int i=0;i<nums.Length;i++){
int imp= target-nums[i];
if(dic.ContainsKey(imp)&&dic[imp]!=i){
return new int[]{i, dic[imp]};
}
if(!dic.ContainsKey(nums[i])){
dic.Add(nums[i],i);
}
}
return new int[]{0, 0};
}
}
```

-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
23 changes: 23 additions & 0 deletions problems/0202.快乐数.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -385,5 +385,28 @@ bool isHappy(int n){
return bHappy;
}
```

C#:
```csharp
public class Solution {
private int getSum(int n) {
int sum = 0;
//每位数的换算
while (n > 0) {
sum += (n % 10) * (n % 10);
n /= 10;
}
return sum;
}
public bool IsHappy(int n) {
HashSet <int> set = new HashSet<int>();
while(n != 1 && !set.Contains(n)) { //判断避免循环
set.Add(n);
n = getSum(n);
}
return n == 1;
}
}
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
19 changes: 19 additions & 0 deletions problems/0242.有效的字母异位词.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,25 @@ impl Solution {
}
}
```

C#:
```csharp
public bool IsAnagram(string s, string t) {
int sl=s.Length,tl=t.Length;
if(sl!=tl) return false;
int[] a = new int[26];
for(int i = 0; i < sl; i++){
a[s[i] - 'a']++;
a[t[i] - 'a']--;
}
foreach (int i in a)
{
if (i != 0)
return false;
}
return true;
}
```
## 相关题目

* 383.赎金信
Expand Down
18 changes: 18 additions & 0 deletions problems/0349.两个数组的交集.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,24 @@ int* intersection1(int* nums1, int nums1Size, int* nums2, int nums2Size, int* re
}
```

C#:
```csharp
public int[] Intersection(int[] nums1, int[] nums2) {
if(nums1==null||nums1.Length==0||nums2==null||nums1.Length==0)
return new int[0]; //注意数组条件
HashSet<int> one = Insert(nums1);
HashSet<int> two = Insert(nums2);
one.IntersectWith(two);
return one.ToArray();
}
public HashSet<int> Insert(int[] nums){
HashSet<int> one = new HashSet<int>();
foreach(int num in nums){
one.Add(num);
}
return one;
}
```
## 相关题目

* 350.两个数组的交集 II
Expand Down
17 changes: 17 additions & 0 deletions problems/0383.赎金信.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,22 @@ impl Solution {
}
```

C#:
```csharp
public bool CanConstruct(string ransomNote, string magazine) {
if(ransomNote.Length > magazine.Length) return false;
int[] letters = new int[26];
foreach(char c in magazine){
letters[c-'a']++;
}
foreach(char c in ransomNote){
letters[c-'a']--;
if(letters[c-'a']<0){
return false;
}
}
return true;
}
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
27 changes: 27 additions & 0 deletions problems/0454.四数相加II.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,32 @@ impl Solution {
}
```

C#:
```csharp
public int FourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
Dictionary<int, int> dic = new Dictionary<int, int>();
foreach(var i in nums1){
foreach(var j in nums2){
int sum = i + j;
if(dic.ContainsKey(sum)){
dic[sum]++;
}else{
dic.Add(sum, 1);
}

}
}
int res = 0;
foreach(var a in nums3){
foreach(var b in nums4){
int sum = a+b;
if(dic.TryGetValue(-sum, out var result)){
res += result;
}
}
}
return res;
}
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

AltStyle によって変換されたページ (->オリジナル) /