![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
tyustli
不抛弃,不放弃
展开
-
leecode--位1的个数
C 源码 #include "stdio.h" int hammingWeight(int n) { int dist = 0; while (n != 0) { dist++; n &= n - 1; } return dist; } int main(void) { printf("%d \r\n", hammingWeight(0b0000000000000000000000001011)); pr原创 2021-03-31 16:25:11 · 83 阅读 · 0 评论 -
leecode--汉明距离
C 源码 #include "stdio.h" int hamming_distance(unsigned x, unsigned y) { int dist = 0; unsigned val = x ^ y; // Count the number of bits set while (val != 0) { // A bit is set, so increment the count and clear the bit d原创 2021-03-31 16:18:01 · 95 阅读 · 0 评论 -
leetcode--两数相加
C 源码 #include <stdio.h> #include <malloc.h> #include <assert.h> struct ListNode { int val; struct ListNode *next; }; static struct ListNode *newNode(int value) { struct ListNode *ptr = NULL; ptr = (struct ListNode *)mal原创 2021-03-04 19:36:14 · 90 阅读 · 1 评论 -
leetcode--两数之和
C源码 #include <stdio.h> #include <malloc.h> /** * Note: The returned array must be malloced, assume caller calls free(). */ int *twoSum(int *nums, int numsSize, int target, int *returnSize) { int *result = NULL; result = (int *)mallo原创 2021-03-01 21:49:19 · 84 阅读 · 1 评论