- 两数之和
给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。
import java.util.HashMap;
import java.util.Map;
class Solution {
public int[] twoSum(int[] nums, int target) {
int[] indexs = new int[2];
HashMap list = new HashMap();
for(int i = 0; i = 2) {
if(!y.substring(0, 1).equals(y.substring(y.length()-1)))
return false;
y = y.substring(1, y.length()-1);
}
return true;
}
}
class Solution {
//数字反转
public boolean isPalindrome(int x) {
if(x = 1) {
int flag = 1;
char beg = s.charAt(0);
if(s.length() >= 2) {
char next = s.charAt(1);
if(beg == 'I') {
if(next == 'X' || next == 'V')
flag = -1;
}else if(beg == 'X') {
if(next == 'L' || next == 'C')
flag = -1;
}
else if(beg == 'C')
if(next == 'D' || next == 'M')
flag = -1;
}
result += flag * hashMap.get(beg);
s = s.substring(1);
}
return result;
}
}
//秀儿版本
class Solution {
public int romanToInt(String s) {
s = s.replace("IV","a");
s = s.replace("IX","b");
s = s.replace("XL","c");
s = s.replace("XC","d");
s = s.replace("CD","e");
s = s.replace("CM","f");
int res = 0;
for (int i = 0; i
关注
打赏
热门博文
- 【Leetcode】剑指Offer 34:二叉树中和为某一值的路径
- 【Leetcode】剑指Offer 33:二叉搜索树的后序遍历序列
- 【Leetcode】剑指Offer 32-III: 从上到下打印二叉树 III
- 【Leetcode】剑指Offer 32-II: 从上到下打印二叉树 II
- 【Leetcode】剑指Offer 32-I:从上到下打印二叉树
- 【Leetcode】剑指Offer 31:栈的压入、弹出序列
- 【Leetcode】剑指Offer 30:包含min函数的栈
- 【Leetcode】剑指Offer 29:顺时针打印矩阵
- 【Leetcode】剑指Offer 28:对称的二叉树
- 【Leetcode】剑指Offer 27:二叉树的镜像