- 博客(13)
- 资源 (3)
- 收藏
- 关注
原创 LeetCode_24_Swap Nodes in Pairs
题目描述Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You ma
2017-10-27 17:18:27 185
原创 LeetCode_21_Merge Two Sorted Lists
题目描述Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.代码实现(两种方式) 第一种:使用非递归的形式 主要思想就是:建立一个头结点,然后依次比较两个链表节点的
2017-10-27 09:10:09 160
原创 LeetCode_19_Remove Nth Node From End of List
题目描述Given a linked list, remove the nth node from the end of list and return its head.示例 Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked lis
2017-10-26 16:03:32 196
原创 LeetCode_11_Container With Most Water
题目描述Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two
2017-10-26 14:26:57 282
原创 leetCode_15_3Sum
题目描述Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain du
2017-10-26 10:42:57 165
原创 分苹果
题目描述n 只奶牛坐在一排,每个奶牛拥有 ai 个苹果,现在你要在它们之间转移苹果,使得最后所有奶牛拥有的苹果数都相同,每一次,你只能从一只奶牛身上拿走恰好两个苹果到另一个奶牛上,问最少需要移动多少次可以平分苹果,如果方案不存在输出 -1。输入描述每个输入包含一个测试用例。每个测试用例的第一行包含一个整数 n(1 <= n <= 100),接下来的一行包含 n 个整数 ai(1 <= ai <= 1
2017-10-23 11:51:47 227
原创 异常:Exception in thread "main" java.util.ConcurrentModificationException
错误代码: Map<Integer,Integer> map = new HashMap<>(); map.put(1,1); map.put(2,2); map.put(3,3); map.put(4,4); for (Map.Entry<Integer,Integer> entry : map.entrySet())
2017-10-19 16:57:38 295
原创 数组中找到出现次数大于N/K的数
说明此题操作 Map 的时候,推荐使用 Entry 集合,尽量不要使用 map.get(), map.keySet() 等。import java.util.HashMap;import java.util.LinkedList;import java.util.List;import java.util.Map;/** * Created by Cser_W on 2017/10/19.
2017-10-19 16:50:38 373
原创 LeetCode_697_Degree of an Array
题目描述Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the smallest possible length of a
2017-10-16 21:26:13 840
原创 偶串
题目描述:如果一个字符串由两个相同字符串连接而成,就称这个字符串是偶串。例如”xyzxyz”和”aaaaaa”是偶串,但是”ababab”和”xyzxy”却不是。 牛牛现在给你一个只包含小写字母的偶串s,你可以从字符串s的末尾删除1和或者多个字符,保证删除之后的字符串还是一个偶串,牛牛想知道删除之后得到最长偶串长度是多少。 输入描述:输入包括一个字符串s,字符串长度length(2 ≤ lengt
2017-10-13 20:17:15 192
原创 彩色瓷砖
题目描述:链接:https://www.nowcoder.com/questionTerminal/31af498841fd491886b8dee6ebde9768 来源:牛客网牛牛喜欢彩色的东西,尤其是彩色的瓷砖。牛牛的房间内铺有L块正方形瓷砖。每块砖的颜色有四种可能:红、绿、蓝、黄。给定一个字符串S, 如果S的第i个字符是’R’, ‘G’, ‘B’或’Y’,那么第i块瓷砖的颜色就分别是红、绿、
2017-10-12 22:04:58 267
原创 NPE(null point Exception)产生的场景
public int f() {return Integer 对象},如果为 null,自动解箱抛 NPE。数据库的查询结果可能为 null。集合里的元素即使 isNotEmpty,取出的数据元素也可能为 null。远程调用对象时,一律要求进行空指针判断,防止 NPE。对于Session 中获取的数据,建议 NPE 检查,避免空指针。级联调用 obj.getA().getB().getC(
2017-10-12 21:08:51 2158 1
原创 leetCode_637_AverageOfLevelsInBinaryTree
题目描述 Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array./** * Definition for a binary tree node. * public class TreeNode { * int val;
2017-10-09 15:11:38 151
深入理解Java虚拟机(第二版)
2017-09-19
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人