【【LeetCode/LintCode】Facebook面试题:子集 II】教程文章相关的互联网学习教程文章

【LeetCode-面试算法经典-Java实现】【034-Search for a Range(搜索一个范围)】【代码】【图】

【034-Search for a Range(搜索一个范围)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1]. For example, Given [5, 7, 7, 8, 8, 10] and target value 8, return [3, ...

【LeetCode-面试算法经典-Java实现】【225-Implement Stack using Queues(用队列实现栈操作)】【代码】【图】

【225-Implement Stack using Queues(用队列实现栈操作)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】代码下载【https://github.com/Wang-Jun-Chao】原题  Implement the following operations of a stack using queues. push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. empty() – Return whether the stack is empty. Notes: You mus...

【LeetCode-面试算法经典-Java实现】【101-Symmetric Tree(对称树)】【代码】【图】

【101-Symmetric Tree(对称树)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1/ 2 2/ \ / 3 4 4 3  But the following is not: 1/ 2 2\ 3 3  Note: Bonus points if you could solve it both recursively and iteratively.题目大意...

【LeetCode-面试算法经典-Java实现】【070-Set Matrix Zeroes(矩阵置零)】【代码】【图】

【070-Set Matrix Zeroes(矩阵置零)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 题目大意  给定一个m*n的矩阵,如果某个位置是0。将对应的行和列设置为0。 解题思路  先对矩阵进行扫描,标记要进行置0的行和列,对要进行置0的行在第0列上进行标记,对置0的列在第0行上进行标标记。同时还要两变量记录...

LeetCode | 面试题03. 数组中重复的数字【剑指Offer】【Easy】【Python】【数组】【哈希表】【排序】【代码】

LeetCode 面试题03. 数组中重复的数字【剑指Offer】【Easy】【Python】【数组】【哈希表】【排序】问题力扣找出数组中重复的数字。在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。示例 1:输入: [2, 3, 1, 0, 2, 5, 3] 输出:2 或 3 限制:2 <= n <= 100000思路解法一哈希表遍历数组,未出现过的...

leetcode-面试题44-数字序列某位中的数字【代码】【图】

题目描述: 方法一:找规律class Solution {publicint findNthDigit(int n) {int digit = 1;long start = 1;long count = 9;while(n > count){n -= count;digit += 1;start *= 10;count = digit * start * 9;}long num = start + (n - 1) /digit;return Long.toString(num).charAt((n-1) % digit) - ‘0‘;} } 原文:https://www.cnblogs.com/oldby/p/12904852.html

LeetCode 面试题06. 从尾到头打印链表【代码】

题目链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。示例 1:输入:head = [1,3,2]输出:[2,3,1] 限制:0 <= 链表长度 <= 10000 1/**2 * Definition for singly-linked list.3 * struct ListNode {4 * int val;5 * struct ListNode *next;6 * };7*/ 8 9/** 10 * Note: The returned array must be malloced, assum...

LeetCode 剑指offer 面试题05. 替换空格【代码】

请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 示例 1:输入:s = "We are happy."输出:"We%20are%20happy." 限制:0 <= s 的长度 <= 10000来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 // 新建空的字符串 逐个遍历原字符串class Solution { public:string replaceSpace(string s) {string res;for(auto i...

【LeetCode/LintCode】 题解丨谷歌高频面试题:最大假期天数【代码】

LintCode想让它最好的员工之一选择在N个城市间旅行来收集算法问题。但是只工作不玩耍,聪明的孩子也会变傻,你可以在某些特定的城市并且一个星期里去度假。你的工作是安排旅行,尽可能多的假期,但是有一些规则和限制你需要遵守。规则和限制:您只能在1个城市中旅行,由0到N-1的索引表示。一开始,你周一在城市0。这些城市都是通过航班连接起来的。这些航班被表示为N*N矩阵(非必要对称),称为代表航空公司从城市i到j城市状态的fligh...

【LeetCode-面试算法经典-Java实现】【057-Insert Interval(插入区间)】【代码】【图】

【057-Insert Interval(插入区间)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1: Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9]. Example 2: Given [1,2],[3,5]...

【LeetCode-面试算法经典-Java实现】【024-Swap Nodes in Pairs(成对交换单链表的结点)】【代码】【图】

【024-Swap Nodes in Pairs(成对交换单链表的结点)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed. 题目大意  给定一...

【LeetCode-面试算法经典-Java实现】【114-Flatten Binary Tree to Linked List(二叉树转单链表)】【代码】【图】

【114-Flatten Binary Tree to Linked List(二叉树转单链表)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a binary tree, flatten it to a linked list in-place. For example, Given 1/ 2 5/ \ 3 4 6  The flattened tree should look like: 1 2 3 4 5 6题目大意  给定一棵二叉树,将它转成单链表,使用原地算法。 解题思...

LeetCode 面试题05. 替换空格【代码】

题目链接:https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/请实现一个函数,把字符串 s 中的每个空格替换成"%20"。示例 1:输入:s = "We are happy."输出:"We%20are%20happy."限制:0 <= s 的长度 <= 10000 1char* replaceSpace(char* s){2int len=strlen(s);3int i,j=0,cnt=0;4for(i=0;i<len;i++){5if(s[i]==‘‘) cnt++;6 }7char *ns=(char *)malloc(sizeof(char)*(len+3*(cnt+1)));8for(i=0;i<len;i++){9if(s[i]!...

LeetCode面试题29.顺时针打印矩阵【图】

题目要求 算法分析模拟打印路径,设置一个枚举变量表示索引运动方向,每次运动时根据运动方向判断下一个位置,改变方向的条件是,下一步会运动到边界,或者运动到已经去过的位置,(可以把已经去过的位置赋值为特殊值,方便判断),如果连续改变两次方向则代表打印路径结束。代码展示(C#)public class Solution { public enum Direction{ right, down, left, up }; public int[] SpiralOrder(in...

【LeetCode-面试算法经典-Java实现】【009-Palindrome Number(回文数)】【代码】【图】

【009-Palindrome Number(回文数)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Determine whether an integer is a palindrome. Do this without extra space. 题目大意  判断一个数字是否是回访字数,不要使用额外的空间。 解题思路  为了不使用额外的空间,参考了其它的解决,那些解法看起来在isPalindrome方法中没有使用额外参数,但是却使用了方法调用,这个比一个整数消耗的空间更多 ,并没有达到...