当前位置:网站首页>Double hands of daily practice of Li Kou 2day9
Double hands of daily practice of Li Kou 2day9
2022-06-22 13:42:00 【InfoQ】
Buckle the hands of one practice every day 2Day9
Leetcode283. Move zero
Example 1:
Input : nums = [0,1,0,3,12]
Output : [1,3,12,0,0]
Example 2:
Input : nums = [0]
Output : [0]
Their thinking
Source code
class Solution {
public void moveZeroes(int[] nums) {
if(nums==null||nums.length==0){
return;
}
int[] tmp=new int[nums.length];
int j=0;
for(int i=0;i<nums.length;i++){
if(nums[i]!=0){
tmp[j]=nums[i];
j++;
}
}
for(int i=0;i<nums.length;i++){
nums[i]=tmp[i];
}
}
}
🥰Leetcode167. The sum of two numbers and two input a valid array
Example 1:
Input :numbers = [2,7,11,15], target = 9
Output :[1,2]
explain :2 And 7 The sum is equal to the number of targets 9 . therefore index1 = 1, index2 = 2 . return [1, 2] .
Example 2:
Input :numbers = [2,3,4], target = 6
Output :[1,3]
explain :2 And 4 The sum is equal to the number of targets 6 . therefore index1 = 1, index2 = 3 . return [1, 3] .
Example 3:
Input :numbers = [-1,0], target = -1
Output :[1,2]
explain :-1 And 0 The sum is equal to the number of targets -1 . therefore index1 = 1, index2 = 2 . return [1, 2] .
Their thinking
🤩 Source code
class Solution {
public int[] twoSum(int[] numbers, int target) {
int left=0,right=numbers.length-1;
while(left<right){
int currentSum=numbers[left]+numbers[right];
if(currentSum==target){
return new int[]{left+1,right+1};
}else if(currentSum<target){
left++;
}else{
right--;
}
}
return new int[]{-1,-1};
}
}
summary
I think the article is well written , Like comments, pay attention to a wave , Love you
边栏推荐
- leetcode 1130. Minimum cost spanning tree of leaf value
- Windows下MySQL 8.0.29的详细安装教程,解决找不到VCRUNTIME140_1.dll、plugin caching_sha2_password could not be loaded
- 268. Missing Number
- 卸载MySQL 8
- Writing a contract testing tool from scratch -- database design
- Record the solution of failing to log in after the alicloud ECS instance is restarted (hands-on practice)
- Stored procedures in MySQL
- [cloud native] event publishing and subscription in Nacos -- observer mode
- 基于JSP的图书馆管理系统,包含源码,数据库脚本,项目运行视频教程,毕设论文撰写视频教程
- Write a contract testing tool from scratch
猜你喜欢

leetcode 85. Max rectangle

Leetcode math problems

Redis password modification, startup, view and other operations

【Nacos云原生】阅读源码第一步,本地启动Nacos

240. Search a 2D Matrix II

聊一聊数据库的行存与列存

Istio服务网格中的流量复制

史蒂芬·柯维写给年轻人的高效工作秘笈

HW is around the corner. Can't you read the danger message?

SSM based community garbage classification and transportation management system, high-quality graduation thesis example (can be used directly), source code, database script, project introduction and o
随机推荐
Acwing game 55
Detailed installation tutorial of MySQL 8.0.29 under windows to solve the problem that vcruntime140 cannot be found_ 1.dll、plugin caching_ sha2_ password could not be loaded
“不敢去懷疑代碼,又不得不懷疑代碼”記一次網絡請求超時分析
leetcode LCP 10. Binary tree task scheduling
Writing a contract testing tool from scratch -- database design
Interpretation of the thesis -- factorization meets the neighborhood: a multifaceted collaborative filtering model
【云原生】Nacos中的事件发布与订阅--观察者模式
Getting started with shell Basics
Leetcode interval DP
Alicloud disk performance analysis
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
基于JSP的图书馆管理系统,包含源码,数据库脚本,项目运行视频教程,毕设论文撰写视频教程
Consolidation of common functions of numpy Library
Testing methodology - data driven testing
693. Binary Number with Alternating Bits
Number of times Oracle uses cursor to decompose numbers
"N'osez pas douter du Code, vous devez douter du Code" notez une analyse de délai de demande réseau
Tables converting to latex format
Customer member value analysis
基於SSM的小區垃圾分類和運輸管理系統,高質量畢業論文範例(可直接使用),源碼,數據庫脚本,項目導入運行視頻教程,論文撰寫教程