随笔分类 -  c++

摘要:Source You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that t 阅读全文
posted @ 2022-03-13 14:12 凌雨尘 阅读(52) 评论(0) 推荐(0)
摘要:Source Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preser 阅读全文
posted @ 2022-02-13 13:07 凌雨尘 阅读(74) 评论(0) 推荐(0)
摘要:Source Write a removeDuplicates() function which takes a list and deletes any duplicate nodes from the list. The list is not sorted. For example if th 阅读全文
posted @ 2022-01-09 12:04 凌雨尘 阅读(61) 评论(0) 推荐(0)
摘要:Source Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example Given 1 阅读全文
posted @ 2021-12-05 13:54 凌雨尘 阅读(49) 评论(0) 推荐(0)
摘要:Source Given a sorted linked list, delete all duplicates such that each element appear only once. Example Given 1->1->2, return 1->2. Given 1->1->2->3 阅读全文
posted @ 2021-11-14 12:26 凌雨尘 阅读(45) 评论(0) 推荐(0)
摘要:Source Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant dig 阅读全文
posted @ 2021-09-19 15:10 凌雨尘 阅读(322) 评论(0) 推荐(0)
摘要:Source Ugly number is a number that only have factors 3, 5 and 7. Design an algorithm to find the Kth ugly number. The first 5 ugly numbers are 3, 5, 阅读全文
posted @ 2021-09-12 10:28 凌雨尘 阅读(73) 评论(0) 推荐(0)
摘要:前言 C语言中,结构体内存对齐问题算是比较常见的问题,虽然理解起来不难,但很多时候一不小心就会算错。比如给你一个 struct,让你 sizeof 计算一下需要占用多少字节,往往得到的结果比等于 struct 里面数据成员所占用的字节之和。 例: #include <stdio.h> struct 阅读全文
posted @ 2021-05-23 11:38 凌雨尘 阅读(293) 评论(0) 推荐(0)
摘要:Source 计算 a^n % b,其中a,b和n都是32位的非负整数 题解 数学题,考察整数求模的一些特性,不知道这个特性的话此题一时半会解不出来,本题中利用的关键特性为: (a * b) % p = ((a % p) * (b % p)) % p 即 a 与 b 的乘积模 p 的值等于 a, b 阅读全文
posted @ 2021-03-28 12:50 凌雨尘 阅读(95) 评论(0) 推荐(0)
摘要:Source Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e g , M beco 阅读全文
posted @ 2021-03-07 13:05 凌雨尘 阅读(115) 评论(0) 推荐(0)
摘要:Source Given n, how many structurally unique BSTs (binary search trees) that store values 1...n? Example Given n = 3, there are a total of 5 unique BS 阅读全文
posted @ 2021-02-28 14:23 凌雨尘 阅读(93) 评论(0) 推荐(0)
摘要:Source Write an algorithm which computes the number of trailing zeros in n factorial. Example 11! = 39916800, so the out should be 2 Challenge O(log N 阅读全文
posted @ 2021-02-17 13:58 凌雨尘 阅读(125) 评论(0) 推荐(0)
摘要:Source Determine the number of bits required to convert integer A to integer B Example Given n = 31, m = 14,return 2 (31)10=(11111)2 (14)10=(01110)2 题 阅读全文
posted @ 2021-01-31 13:10 凌雨尘 阅读(114) 评论(0) 推荐(0)
摘要:Source Using O(1) time to check whether an integer n is a power of 2. Example For n=4, return true; For n=5, return false; Challenge O(1) time 题解 咋看起来 阅读全文
posted @ 2021-01-10 16:08 凌雨尘 阅读(103) 评论(0) 推荐(0)
摘要:Source Given 3*n + 1 numbers, every numbers occurs triple times except one, find it. Example Given [1,1,2,3,3,3,2,2,4,1] return 4 Challenge One-pass, 阅读全文
posted @ 2020-10-25 12:39 凌雨尘 阅读(127) 评论(0) 推荐(0)
摘要:Problem 「找单数」系列题,技巧性较强,需要灵活运用位运算的特性。 Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Example Given [1,2,2,1,3,4,3], return 4 Ch 阅读全文
posted @ 2020-10-11 12:27 凌雨尘 阅读(151) 评论(0) 推荐(0)
摘要:实现 int sqrt(int x) 函数 计算并返回 x 的平方根,其中 x 是非负整数。 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。 示例 1: 输入: 4 输出: 2 示例 2: 输入: 8 输出: 2 说明: 8 的平方根是 2.82842..., 由于返回类型是整数,小数 阅读全文
posted @ 2020-09-06 12:38 凌雨尘 阅读(374) 评论(0) 推荐(0)
摘要:Problem There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. Example Given A=[1,2,3,4,5,6] and  阅读全文
posted @ 2020-08-16 12:33 凌雨尘 阅读(180) 评论(0) 推荐(0)
摘要:Problem Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum 阅读全文
posted @ 2020-04-26 12:14 凌雨尘 阅读(108) 评论(0) 推荐(0)
摘要:Problem Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum 阅读全文
posted @ 2020-04-19 13:10 凌雨尘 阅读(112) 评论(0) 推荐(0)