又是好久没有刷题 https://leetcode.com/problems/…
26. Remove Duplicates from Sorted Array
Given a sorted array nums, 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 by modifying …… 阅读全文
Tag Archives: LeetCode
leetcode Hamming Distance
https://leetcode.com/problems/…
盲敲,一遍过,:)
class Solution {
public:
int hammingDistance(int x, int y) {
int res = x ^ y;
int cnt = 0;
while (res) {
if (res % 2) {
cnt++;
}
res /= 2;
}
…… 阅读全文
Single Number II
https://oj.leetcode.com/proble…,承前,http://zrj.me/archives/1344,这个题目是每个数字出现三次,要求找出只出现一次的数字:
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could …… 阅读全文
Single Number
来看这个题,https://oj.leetcode.com/proble…:
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
第一反应就是异或,唯一需要确认的就是异…… 阅读全文
Linked List Cycle
所谓拳不离手曲不离口,算法和基础不能丢。
话说三藏师徒四人辞别女儿国,再上西行路,今天来到。。。啊呸,扯远了。。
今天来看这个,https://oj.leetcode.com/proble…,题目是这么说的
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
这题原…… 阅读全文