Skip to content

Instantly share code, notes, and snippets.

View icameling's full-sized avatar
🎯
Focusing

icameling

🎯
Focusing
View GitHub Profile
@icameling
icameling / plot_results.py
Created November 15, 2022 03:32
plot 3d traj #plot
#!/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
@icameling
icameling / sqrt_float.cpp
Created July 26, 2022 09:05
#面试 #数字开根号
float sqrt_float(float x) {
if (x < 0) {
return -1;
}
float left = x/2, right = x;
if (x < 0.5) {
left = 0;
right = x;
}
@icameling
icameling / sliding-window-maximum.cpp
Created July 19, 2022 14:55
#栈与队列 #滑动窗口最大值
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
@icameling
icameling / evaluate-reverse-polish-notation.cpp
Created July 19, 2022 13:59
#栈与队列 #逆波兰表达式求值
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();
@icameling
icameling / remove-all-adjacent-duplicates-in-string.cpp
Created July 19, 2022 13:48
#栈与队列 #删除字符串中的所有相邻重复项
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]);
}
@icameling
icameling / valid-parentheses.cpp
Created July 19, 2022 13:26
#栈与队列 #有效的括号
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] == '{')
@icameling
icameling / implement-queue-using-stacks.cpp
Created July 19, 2022 12:40
#栈与队列 #用栈实现队列
class MyQueue {
public:
MyQueue() {
}
void push(int x) {
my_deque_.push_back(x);
}
@icameling
icameling / repeated-substring-pattern.cpp
Created July 19, 2022 12:08
#字符串 #重复的子字符串
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])
@icameling
icameling / implement-strstr.cpp
Last active July 19, 2022 11:26
#字符串 #实现strStr
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;
@icameling
icameling / zuo-xuan-zhuan-zi-fu-chuan-lcof.cpp
Created July 19, 2022 07:41
#字符串 #左旋转字符串
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;
}
};