![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java
水中走
这个作者很懒,什么都没留下…
展开
-
160. Intersection of Two Linked Lists
// idea: a+allcommon+b = b + allcommon+a;//a represents the len before the intersect pos in list A;//b represents the len before the intersect pos in list B;//take the lists as a whole, so the tota...原创 2020-04-17 23:13:05 · 108 阅读 · 0 评论 -
Leetcode 189. Rotate Array
Given an array, rotate the array to the right by k steps, where k is non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,...原创 2020-03-28 06:02:04 · 99 阅读 · 0 评论 -
一个简单的突发奇想求众数,LeetCode169. Majority Element
从摩尔投票思想出发:因为题目众数是出现次数超过一半,所以只可能有一个数字出现次数超过一半,就给一个变量num和count;遍历nums:count为0时,重新赋值count不为0时,判断,int a = num==nums[i] ? count++: count–class Solution { public int majorityElement(int[] nums) {...原创 2020-03-27 00:54:32 · 81 阅读 · 0 评论 -
特别好用的二分查找法模板(Python 代码、Java 代码)
https://www.liwei.party/2019/06/18/leetcode-solution-new/search-insert-position/转载 2020-03-12 07:08:01 · 140 阅读 · 0 评论 -
27. Remove Element
Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array...原创 2020-03-12 05:35:56 · 69 阅读 · 0 评论 -
2. array--删除排序数组中的重复项
class Solution { public int removeDuplicates(int[] nums) { int n= nums.length; if (n == 0) return 0; int distinc = 0;//(distinct)不同元素个数,初始为0 for (int i=0; i<n-1;...原创 2020-03-10 11:58:31 · 152 阅读 · 0 评论 -
1.Two Sum
//import the HashMap,Map to avoid the compile error//import java.util.Map;//import java.util.HashMap;public class Solution{ public int[] twoSum(int[]num, int target){ //twoSum方法 //用hashtable,建...原创 2020-03-09 11:48:54 · 93 阅读 · 0 评论 -
IntelliJ IDEA 中 右键运行时没有run
public class CustomerTest { public static void main(~~String[] args~~ ){ //创建Customer对象 Customer c1 = new Customer(); c1.name = "zhangsan"; //c1购物 c1.shop...原创 2020-02-25 07:55:33 · 1933 阅读 · 3 评论