🔥LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解 leetcode.doocs.org Topics javascript java golang csharp algorithms leetcode cpp python3 Re
1publicclassSolution {2/**3*@paramA an integer array sorted in ascending order4*@paramtarget an integer5*@returnan integer6*/7publicintfindPosition(int[] nums,inttarget) {8if(nums ==null|| nums.length == 0) {9return-1;10}1112intstart = 0, end = nums.length - 1;13//要点1: st...
Note: You are not suppose to use the library's sort function for this problem. Example: Input: [2,0,2,1,1,0] Output: [0,0,1,1,2,2] Follow up: A rather straight forward solution is a two-pass algorithm using counting sort. First, iterate the array counting number of 0's, 1'...
import java.util.Arrays; public class Main { public static void main(String[] args) { int[] citations1 = {3, 0, 6, 1, 5}; int result1 = hIndex(citations1); System.out.println(result1); // 输出:3 int[] citations2 = {1, 3, 1}; int result2 = hIndex(citations2); Syst...
1. Description: Notes: 2. Examples: 3.Solutions: 1/**2* Created by sheepcore on 2018-11-113*/4classSolution {5publicString[] reorderLogFiles(String[] logs) {6Comparator<String> myComp =newComparator<String>() {7@Override8publicintcompare(String s1, String s2) {9ints1si = s1.indexOf...
Python3版本 class Solution: def singleNumber(self, nums: List[int]) -> List[int]: x = 0 for num in nums: # 1. 遍历 nums 执行异或运算 x ^= num return x; # 2. 返回出现一次的数字 x 说明: Python中的实现与Java和C类似,使用for循环遍历数组,并通过异或运算找出只出现一次的数字。 复杂...
Could you do it in one-pass, using only O(1) extra memory and without modifying the value of the board? 【解答】要数有多少 battleship,并且要求使用 O(1) 的空间复杂度,还不能修改 board 上的数值。 一行一行遍历,每一行中从左往右遍历。对于每一个点,如果左侧和上方都不是 X,那就...
leetcode刷题(3) Java代码实现 class Solution {public boolean isValid(String s) {Stack stack = new Stack(); for (int i = 0; i < s.length(); i++) {char ch = s.charAt(i); if(ch == '(' || ch == '{' || ch == '[') {stack.push(ch); ...
Java publicclassSolution{publicintlengthOfLongestSubstring(Strings){intmaxLength=0,i=0,j=0;Set<Character>set=newHashSet<>();while(i<s.length()&&j<s.length()){if(set.contains(s.charAt(j))){set.clear();i++;j=i;}else{set.add(s.charAt(j));maxLength=Math.max(maxLength,j-i+1);j...
LeetCode 刷题随手记 - 第一部分 前 256 题(非会员),仅算法题,的吐槽 https://leetcode.com/problemset/algorithms/...