Leetcode C#答案(自编)
程序员文章站
2024-03-22 14:35:16
...
#1两数之和
public class Solution {
public int[] TwoSum(int[] nums, int target)
{
int[] newIntArr = new int[0];
for (int i = 0; i < nums.Length; i++)
{
for (int j = 0; j < nums.Length; j++)
{
if ((i < j) && nums[i] + nums[j] == target)
{
newIntArr = new int[] { i, j };
}
}
}
return newIntArr;
}
}
#9回文数
public class Solution {
public bool IsPalindrome(int x) {
string str = x.ToString();
for (int i = 0; i < str.Length/2; i++)
{
if (str[i] == str[str.Length-1-i])
{
continue;
}
else
{
return false;
}
}
return true;
}
}
上一篇: LeetCode题目以及答案(5)
下一篇: Palindrome Number