136.只出现一次的数字leetcode-cn.com/problems/single-number/?utm_campaign=lcsocial&utm_medium=question&utm_source=zhihu&utm_content=35485418&utm_term=601761277 题目描述:给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。
Actually, the code works well not only for appearing twice, but also appearing even times. In next bolg, I will share you will a more general way to handle this kind of question.
My solution: publicclassSolution {publicintsingleNumber(int[] A) {if(A.length == 0 || A ==null)return0;intret = A[0];for(inti = 1; i < A.length; i++) { ret^=A[i]; }returnret; } } The question: Single Number II Given an array of integers, every element appearsthreetime...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
1365. 有多少小于当前数字的数字 - 给你一个数组 nums,对于其中每个元素 nums[i],请你统计数组中比它小的所有数字的数目。 换而言之,对于每个 nums[i] 你必须计算出有效的 j 的数量,其中 j 满足 j != i 且 nums[j] < nums[i] 。 以数组形式返回答案。 示例 1:
:question: My LeetCode solutions. Contribute to MrHuxu/leetcode development by creating an account on GitHub.
Notes: 🔒 means your subscription of LeetCode Premium Membership is required for reading the question. Question List #TitleDifficultySolution 1 Two Sum Easy Go 2 Add Two Numbers Medium Go 3 Longest Substring Without Repeating Characters Medium Go 9 Palindrome Number Easy Go 11 Container With Most...
Subsets Go Medium O(n^2) O(n) 136. Single Number Go Easy O(n) O(1) 137. Single Number II Go Medium O(n) O(1) 169. Majority Element Go Easy O(n) O(1) 187. Repeated DNA Sequences Go Medium O(n) O(1) 190. Reverse Bits Go Easy O(n) O(1) 191. Number of 1 Bits ...
https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips/ https://leetcode.com/...
题目的意思是判断ransom的词能否由magazine中的字符构成,magazine中每个字符只能使用一次。 思路 思路:这题很简单,之前也做过好多类似的了,可以参考刷题日记36 – Leetcode 242. Valid Anagram的做法。 自加自减运算符拓展: 一开始把11、12行写成了一行,写成if(--count[x-'a']<0),就过了; 写成if(count[x...