Skip to content

Instantly share code, notes, and snippets.

@freelze
freelze / 485_Max Consecutive Ones.cpp
Last active September 21, 2017 09:25
Runtime: 46 ms , Your runtime beats 15.21 % of cpp submissions.
#include <iostream>
#include <vector>
using namespace std;
class Solution
{
public:
int findMaxConsecutiveOnes(vector<int>& nums)
{
int count = 0, max = 0;
@freelze
freelze / 461_Hamming Distance.cpp
Last active September 21, 2017 09:26
Runtime: 6 ms , Your runtime beats 2.52 % of cpp submissions.
class Solution {
public:
int hammingDistance(int x, int y) {
const int MAX = 10000;
bool two_x[MAX] = {0}, two_y[MAX] = {0};
int i = MAX-1, j = MAX-1;
int point = 0;
while(x>=2)
{
@freelze
freelze / 561_Array Partition.cpp
Last active September 21, 2017 09:27
Runtime: 109 ms , Your runtime beats 4.36 % of cpp submissions.
#include <algorithm>
class Solution {
public:
int arrayPairSum(vector<int>& nums) {
vector<int>::size_type sz = nums.size();
sort(nums.begin(),nums.end());
int total = 0;
for(int i=0;i<sz;i+=2)
{
total+=nums[i];