目录
三、19. 删除链表的倒数第 N 个结点 - 力扣(LeetCode)
一、对称之美 (nowcoder.com)
清脆的声音加上可爱的牛牛
牛客毕竟麻烦的一点就是需要自己控制输入和输出
题目的意思就是 判断一个字符数组是不是回文的
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int totalNumber = in.nextInt();
while (totalNumber-- > 0) {
int number = in.nextInt();
in.nextLine();
String[] strs = new String[number];
for (int i = 0; i < strs.length; i++) {
strs[i] = in.nextLine();
}
System.out.println(f(strs));
}
}
public static String f(String[] strs) {
int left = 0;
int right = strs.length - 1;
while (left < right) {
int[] hash = new int[26];
char[] ch = strs[left].toCharArray();
for (char val : ch) {
hash[val - 'a']++;
}
boolean flg = true;
for (char val : strs[right].toCharArray()) {
if (hash[val - 'a'] > 0) {
flg = false;
break;
}
}
if (flg) {
return "No";
}
left++;
right--;
}
return "Yes";
}
二、经此一役小红所向无敌 (nowcoder.com)
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long a = in.nextInt();
long h = in.nextInt();
long b = in.nextInt();
long k = in.nextInt();
long total = 0;
while (h > 0 && k > 0) {
total += b;
total += a;
h -= b;
k -= a;
}
if (h > 0) {
total += 10 * a;
}
if (k > 0) {
total += 10 * b;
}
System.out.println(total);
}
类型需要好好考虑一下用long
三、19. 删除链表的倒数第 N 个结点 - 力扣(LeetCode)
public ListNode removeNthFromEnd(ListNode head, int n) {
int len= 0;
ListNode cur = head;
while(cur != null){
cur = cur.next;
len++;
}
int move = len - n - 1;
cur = head;
if(move == -1){
head = head.next;
}else{
while(move > 0){
cur = cur.next;
move--;
}
cur.next = cur.next.next;
}
return head;
}