力扣
文章平均质量分 90
养兔兔也
这个作者很懒,什么都没留下…
展开
-
力扣位运算简单java
多数元素给定一个大小为 n 的数组,找到其中的多数元素。多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素。你可以假设数组是非空的,并且给定的数组总是存在多数元素。示例 1:输入:[3,2,3]输出:3示例 2:输入:[2,2,1,1,1,2,2]输出:2位运算c++class Solution {public: int majorityElement(vector<int>& nums) { int res = 0; for(i.原创 2021-03-03 17:16:08 · 285 阅读 · 0 评论 -
力扣哈希专题
1.设计哈希表设置哈希集合class MyHashSet { private Bucket[] bucketArray; private int keyRange; /** Initialize your data structure here. */ public MyHashSet() { this.keyRange = 769; this.bucketArray = new Bucket[this.keyRange]; for (int i = 0; i原创 2020-12-04 08:39:48 · 173 阅读 · 0 评论 -
力扣字符串专题
1.最长公共前缀编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 “”。示例 1:输入: [“flower”,“flow”,“flight”]输出: “fl”class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length ==0) return ""; String pub = strs[0]; for(int原创 2020-12-02 15:22:07 · 378 阅读 · 1 评论 -
力扣数组专题
1.移动零移动零给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。示例:输入: [0,1,0,3,12]输出: [1,3,12,0,0]双指针法快慢指针class Solution { public void moveZeroes(int[] nums) { int n = nums.length, left = 0, right = 0; while (right < n) {原创 2020-12-01 16:26:12 · 240 阅读 · 0 评论 -
力扣简单题合集(带答案)
1.给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。**class Solution { public int[] twoSum(int[] nums, int target) { int n = nums.length; for (int i = 0; i < n; ++i) { fo原创 2020-11-12 17:53:43 · 7688 阅读 · 2 评论