C++ Exercises: Data Structure II

Exercises: 232. Implement Queue using Stacks Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Solution: take advantage of the features of both stacks #include <iostream> #include <set> #include <vector> #include <algorithm> #include <stack> Read more…

C++ Exercises: Data Structure I

Exercises: 448. Find All Numbers Disappeared in an Array Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.Solution: use set to record all numbers had showed and find the the rest disappeared numbers. Tips: you can also increase Read more…

C++ Exercises: Bit Operation

Exercises: 461. Hamming Distance Calculate the number of positions at which the corresponding bits are different. Solution: Do XOR and find the number of 1. class Solution { public: int hammingDistance(int x, int y) { int tmp = x ^ y; int ans = 0; while( tmp > 0 ){ if( Read more…

C++ Exercises: Bucket Sort

Sort all numbers by their counts and display the numbers one by one. These count sets look like different buckets.

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X