随笔分类 - 公司真题
摘要:第一轮算法题:每隔N个节点反转单链表 void reverse(ListNode* pHead, int n){ if(pHead == nullptr) return ; // 先求出链表总长度 int len = 0; ListNode* pNode = pHead; while(pNode !
阅读全文
摘要:第一题 有效的括号 leetcode原题,但我一直80%,后面发现是可以多行输入的,猝。。。 public static void main(String[] args) { // TODO Auto-generated method stub // 定义辅助栈 Stack<Character> s
阅读全文
摘要:1 求疫情聚集区域的个数 其实就是求连续的1的区域个数,简单DFS。 int mapp[110][110]; int dfs(int rows, int cols, int x, int y){ if((x < 0) || (x >= cols) || (y < 0) || (y >= rows)
阅读全文
摘要:第一题:电报破解 其实就是字符串模拟,给一个字符串(含空格),以及反转的长度。最终将字符串破解。 #include <iostream> #include <vector> #include <stack> #include <string> #include <cstring> #include
阅读全文
摘要:0 有效的括号 class Solution { public boolean isValid(String s){ Stack<Character> stack = new Stack<Character>(); for(char c : s.toCharArray()){ if(c == '('
阅读全文