This file contains hidden or 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
#!/usr/bin/python | |
# | |
# Plots the results from the 3D pose graph optimization. It will draw a line | |
# between consecutive vertices. The commandline expects two optional filenames: | |
# | |
# ./plot_results.py --initial_poses filename --optimized_poses filename | |
# | |
# The files have the following format: | |
# ID x y z q_x q_y q_z q_w |
This file contains hidden or 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
float sqrt_float(float x) { | |
if (x < 0) { | |
return -1; | |
} | |
float left = x/2, right = x; | |
if (x < 0.5) { | |
left = 0; | |
right = x; | |
} |
This file contains hidden or 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
class Solution { | |
public: | |
vector<int> maxSlidingWindow(vector<int>& nums, int k) { | |
// a b | |
// 5 1 2 1 5 2 | |
// [1] 5 * 2 * 5 2 | |
// 5 1 3 5 1 0 | |
// [2] 5 1 5 1 |
This file contains hidden or 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
class Solution { | |
public: | |
int evalRPN(vector<string>& tokens) { | |
stack<int> nums; | |
for (const auto& op : tokens) { | |
if (op == "+" || op == "-" || op == "*" || op == "/") { | |
int rht = nums.top(); | |
nums.pop(); | |
int lft = nums.top(); | |
nums.pop(); |
This file contains hidden or 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
class Solution { | |
public: | |
string removeDuplicates(string s) { | |
stack<char> str_ret; | |
for (int i = 0; i < s.size(); ++i) { | |
if (!str_ret.empty() && s[i] == str_ret.top()) { | |
str_ret.pop(); | |
} else { | |
str_ret.push(s[i]); | |
} |
This file contains hidden or 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
class Solution { | |
public: | |
bool isValid(string s) { | |
stack<int> check; | |
map<char, char> bracket_map; | |
bracket_map['('] = ')'; | |
bracket_map['['] = ']'; | |
bracket_map['{'] = '}'; | |
for (int i = 0; i < s.size(); ++i) { | |
if (s[i] == '(' || s[i] == '[' || s[i] == '{') |
This file contains hidden or 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
class MyQueue { | |
public: | |
MyQueue() { | |
} | |
void push(int x) { | |
my_deque_.push_back(x); | |
} | |
This file contains hidden or 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
class Solution { | |
public: | |
void get_pmt(const string& s, int*pmt) { | |
pmt[0] = 0; | |
int j = 0; | |
for (int i = 1; i < s.size(); ++i) { | |
while (j > 0 && s[i] != s[j]) | |
j = pmt[j - 1]; | |
if (s[i] == s[j]) |
This file contains hidden or 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
class Solution { | |
public: | |
int strStr(string haystack, string needle) { | |
if (haystack.size() < needle.size()) | |
return -1; | |
if (needle.size() == 0) | |
return 0; | |
for (int i = 0; i < haystack.size() - needle.size() + 1; ++i) { | |
if (haystack[i] == needle[0]) { | |
int k = 0; |
This file contains hidden or 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
class Solution { | |
public: | |
string reverseLeftWords(string s, int n) { | |
reverse(s.begin(), s.end()); | |
reverse(s.begin(), s.begin() + s.size() - n); | |
reverse(s.begin() + s.size() - n, s.end()); | |
return s; | |
} | |
}; |
NewerOlder