-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfb526f
commit a7fff62
Showing
26 changed files
with
294 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "Hamming Distance", | ||
"id": "hamming-distance", | ||
"discuss_link": "http://www.fgdsb.com/2015/01/03/hamming-distance/", | ||
"desc": "<p>Write a function to calculate Hamming distance between two integers</p>", | ||
"difficulty": "Easy", | ||
"source": "Microsoft", | ||
"time": "2015-02-19 22:14:25", | ||
"tags": [ | ||
"Math" | ||
], | ||
"code_cpp": "int hamming(int a , int b) {\n}", | ||
"code_java": "public class Solution {\n public int hamming(int a , int b) {\n }\n}", | ||
"code_ruby": "# @param a: integer, b: integer\n# @return integer\ndef hamming(a, b)\nend", | ||
"code_python": "# @param a: integer, b: integer\n# @return integer\ndef hamming(a, b):", | ||
"code_lua": "-- @param a: integer, b: integer\n-- @return integer\nfunction hamming(a, b)\nend", | ||
"in_type_cpp": [ | ||
"" | ||
], | ||
"ret_type_cpp": "", | ||
"out_type_cpp": "", | ||
"judge_type_cpp": "equal", | ||
"in_type_java": [ | ||
"" | ||
], | ||
"ret_type_java": "", | ||
"out_type_java": "", | ||
"judge_type_java": "equal", | ||
"judge_type_ruby": "equal", | ||
"judge_type_python": "equal", | ||
"judge_type_lua": "equal", | ||
"judge_call": "function(@)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require './common' | ||
require '../ruby/common' | ||
|
||
class Test_hamming_distance < TestBase | ||
def initialize(name) | ||
super(name) | ||
end | ||
|
||
def add_test | ||
end | ||
|
||
def gen_tests | ||
@test_in, @test_out = [[]], [] | ||
end | ||
end | ||
|
||
Test_hamming_distance.new 'hamming-distance' |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
/* | ||
class Iterator { | ||
public: | ||
int get_next(); | ||
bool has_next(); | ||
}; | ||
*/ | ||
|
||
class ZigzagIterator { | ||
public: | ||
ZigzagIterator(Iterator& a, Iterator& b) :_its{a,b} { | ||
_pointer = a.has_next() ? 0 : 1; | ||
vector<int> longest_subarray(vector<int>& arr) { | ||
cout << arr << endl; | ||
int sum = 0, length = 0, begin = -1; | ||
unordered_map<int, int> record = {{0,-1}}; | ||
for(int i = 0; i < arr.size(); ++i) { | ||
sum += arr[i]; | ||
if(record.count(sum)) { | ||
auto first = record[sum]; | ||
if(i - first > length) { | ||
length = i - first; | ||
begin = first + 1; | ||
} | ||
} else { | ||
record[sum] = i; | ||
} | ||
} | ||
|
||
int get_next() { | ||
int ret = _its[_pointer].get_next(), old = _pointer; | ||
do { | ||
if(++_pointer >= 2) _pointer = 0; | ||
} while(!_its[_pointer].has_next() && _pointer != old); | ||
return ret; | ||
} | ||
|
||
bool has_next() { return _its[_pointer].has_next(); } | ||
private: | ||
Iterator _its[2]; | ||
int _pointer; | ||
}; | ||
if(begin < 0) return {}; | ||
else return vector<int>(arr.begin()+begin, arr.begin()+begin+length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,5 @@ | ||
package judge;import java.util.*;import java.lang.*;import java.io.*;import datastruct.*; /* | ||
public class Iterator { | ||
public int get_next(); | ||
public boolean has_next(); | ||
} | ||
*/ | ||
|
||
public class PeekIterator { | ||
public PeekIterator(Iterator it) { | ||
} | ||
|
||
public int peek() { | ||
return 1; | ||
} | ||
|
||
public boolean has_next() { | ||
return false; | ||
} | ||
|
||
public int get_next() { | ||
return 2; | ||
package judge;import java.util.*;import java.lang.*;import java.io.*;import datastruct.*; public class Solution { | ||
public List<Integer> longest_seq(int[][] mat) { | ||
return new ArrayList<Integer>(); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package.path = package.path .. ';/Users/yanxingwang/Projects/node_proj/fgdsb_judge/judge/lua/?.lua;' | ||
require "common" | ||
require "tests/zigzag-iterator" | ||
require "tests/peek-iterator" | ||
judge() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,5 @@ | ||
from common import * | ||
# class Iterator: | ||
# def get_next(self): | ||
# ... | ||
# | ||
# def has_next(self): | ||
# ... | ||
|
||
class ZigzagIterator: | ||
# @param i0: Iterator object, i1: Iterator object | ||
def __init__(self, i0, i1): | ||
self.its = [i0,i1] | ||
if i0.has_next(): self.pointer = 0 | ||
else: self.pointer = 1 | ||
|
||
# @return boolean | ||
def has_next(self): | ||
return self.its[self.pointer].has_next() | ||
|
||
# @return integer | ||
def get_next(self): | ||
ret, old = self.its[self.pointer].get_next(), self.pointer; | ||
while True: | ||
self.pointer = (self.pointer + 1) % 2 | ||
if self.its[self.pointer].has_next() or self.pointer == old: break | ||
return ret | ||
def plus_num(a, b): | ||
print a | ||
print b | ||
return a + b |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from common import * | ||
from solution import * | ||
from tests.zigzag_iterator import * | ||
from tests.a_plus_b import * | ||
|
||
judge() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,16 @@ | ||
# class Iterator | ||
# def get_next() | ||
# ... | ||
# end | ||
# | ||
# def has_next() | ||
# ... | ||
# end | ||
# end | ||
# class TreeNode | ||
# attr_accessor :left, :right, :val | ||
# def initialize(v) | ||
# @val, @left, @right = v, nil, nil | ||
# end | ||
|
||
class ZigzagIterator | ||
# @param i0: Iterator object, i1: Iterator object | ||
def initialize(i0, i1) | ||
@its, @pointer = [i0,i1], i0.has_next() ? 0 : 1 | ||
end | ||
|
||
# @return boolean | ||
def has_next() | ||
@its[@pointer].has_next() | ||
end | ||
|
||
# @return integer | ||
def get_next() | ||
ret, old = @its[@pointer].get_next, @pointer; | ||
loop do | ||
@pointer = (@pointer + 1) % 2 | ||
break if @its[@pointer].has_next or @pointer == old | ||
end | ||
ret | ||
end | ||
# @param root, TreeNode | ||
# @param m,n, integer | ||
# @return TreeNode | ||
def lca(root, m, n) | ||
return nil if root.nil? | ||
return root if root.val == m or root.val == n | ||
l, r = lca(root.left, m, n), lca(root.right, m, n) | ||
return root if l and r | ||
return l ? l : r | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
require './judge/ruby/common' | ||
require './judge/ruby/solution' | ||
require './judge/ruby/tests/zigzag-iterator' | ||
require './judge/ruby/tests/lca-1' | ||
|
||
judge |
Oops, something went wrong.