`
随便小屋
  • 浏览: 106096 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论
文章列表

LeetCode-15-3Sum*

  3Sum       来自 <https://leetcode.com/problems/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:   Elements in a triplet (a,b,
Minimum Size Subarray Sum   来自 <https://leetcode.com/problems/minimum-size-subarray-sum/> Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead. For example, given the array [2,3,1, ...
Contains Duplicate 来自 <https://leetcode.com/problems/contains-duplicate/> Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.   题 ...
Contains Duplicate II 来自 <https://leetcode.com/problems/contains-duplicate-ii/>   Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k.   题目解读 给定一个整型数 ...
Summary Ranges   来自 <https://leetcode.com/problems/summary-ranges/> Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. Credits: Special thanks to @jianchao. ...
Majority Element   来自 <https://leetcode.com/problems/majority-element/>   Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in th ...
Merge Sorted Array     来自 <https://leetcode.com/problems/merge-sorted-array/> Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional element ...
Pascal's Triangle II     来自 <https://leetcode.com/problems/pascals-triangle-ii/> Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note:
Pascal's Triangle   来自 <https://leetcode.com/problems/pascals-triangle/> Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [      [1],     [1,1],    [1,2,1],   [1,3,3,1],  [1,4,6,4,1] ]   题目解读: 杨辉三角问题,指的是三角形的顶层是1,每一层最两侧的元素也是1
Plus One   来自 <https://leetcode.com/problems/plus-one/> Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. 题目解读: 给定一个非负数,存在一个数组中,数组中的每个元素标识该非负数的一位,给这个数进行加1运算。非负数的最 ...
  Remove Duplicates from Sorted Array II       来自 <https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/>   Follow up for "Remove Duplicates":   What if duplicates are allowed at most twice?   For example,   Given sorted array nums = [1,1,1,2,2,3],   ...
  Remove Duplicates from Sorted Array       Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.   Do not allocate extra space for another array, you must do this in place with constant memory.   For example,   Given inpu ...
Remove Element   Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. 题目解读: 给定一个数组和一个元素,删除该数组中所有的次元素并且返回新的长度,数组中元素的位置可以改变。 解析:两种解决方法 解法一:按照最常规的方法,从头到尾遍历整 ...
Rotate Array: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note:Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.  题目解读: 将包含n个元素的数组向右移动k步, ...
        整数之间的取模求余运算很好求,但几乎没有遇到过对负数进行取模求余,直接看下面代码: /** * * @author Logic * */ public class Test { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("-3%-2=" + -3%-2); System.out.println("3%-2=" + 3%-2); System ...
Global site tag (gtag.js) - Google Analytics