leetcode

C++初学者的一周

℡╲_俬逩灬. 提交于 2020-03-03 16:04:23
C++初学者经验分享 本人大三,第一次在csdn上写博客。一来能分享自己的学习经历,如果我的经历能有幸帮到你的话那是最好不过了!二来是能记录自己的学习过程,方便对自己的编程水平有清晰的阶段化认识。 前情提要!!! 这不是一篇技术帖!这不是一篇技术贴!这不是一篇技术贴! 这更像是一篇生活日志。 目录 为什么学C++ 学C++之前我有怎样的基础 学习过程的收获与进步 为什么学C++ 作为大三学僧,寒假开始应该要开始为考研的事情做准备了。在这之前我上学都是被动上学,小学,初中,高中,大学都被安排的明明白白,从来没想过为什么我要上学,能去上什么样的学校也是看我考试的发挥。得益于我不高不低的智商,和那么一点点外力压迫下的努力,我够最终考上一所211大学。就在我准备要考研的时候,我惊醒了。 “我是谁?我从哪里来?我要到哪里去?” 开个玩笑哈哈。 “我为什么要考研?”,这二十年来我第一次思考自己为什么要升学。 “我不考研的话去做什么?”,就业?创业?(显然不会创业) 这两个问题一直思考下去的结果恰恰就是上文的哲学终极问题。我询问了很多朋友和学长关于要不要考研这件事,他们的回答都大致相同,总结就是两者没有对错,关键看你想要什么。那接下来我当然是思考自己想要什么喽。 思考这个问题对于我来说太难了,我从来不是个能坚定目标的人,做事往往三分钟热度,我现在想要的东西未来还会想要吗?没人能预测未来,那不如就

leetcode -- 面试题10.01、387

久未见 提交于 2020-03-03 14:40:13
文章目录 面试题 10.01. Sorted Merge LCCI Problem Description Solution Method 387.387. First Unique Character in a String Problem Description Solution Method 面试题 10.01. Sorted Merge LCCI Problem Description You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order. Initially the number of elements in A and B are m and n respectively. Example: Input: A = [1,2,3,0,0,0], m = 3 B = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Solution Method 从后往前 void merge(int* A, int ASize, int m, int* B, int BSize, int n) { int count = 0;

本周学习小结(02/03 - 08/03)

强颜欢笑 提交于 2020-03-03 11:31:00
LeetCode 本周无进展。需要及时复习。 学习笔记之LeetCode - 浩然119 - 博客园 https://www.cnblogs.com/pegasus923/p/5528520.html Explore - LeetCode - Design https://leetcode.com/explore/interview/card/top-interview-questions-medium/112/design/ Explore - LeetCode - Math https://leetcode.com/explore/interview/card/top-interview-questions-medium/113/math/ 学习笔记之Problem Solving with Algorithms and Data Structures using Python - 浩然119 - 博客园 https://www.cnblogs.com/pegasus923/p/10454395.html C++ / Database / Git / Linux / Python / MISC 本周有进展。现在对文章选取贵精而不贵多。 学习笔记之C / C++ - 浩然119 - 博客园 https://www.cnblogs.com/pegasus923/p/10437163

【LeetCode题解】2_两数相加

喜欢而已 提交于 2020-03-03 03:23:08
目录 【LeetCode题解】2_两数相加 描述 方法一:小学数学 思路 Java 代码(非递归写法) Java 代码(递归写法) Python 代码(非递归写法) 【LeetCode题解】2_两数相加 描述 给定两个 非空 链表来表示两个非负整数。位数按照 逆序 方式存储,它们的每个节点只存储单个数字。将两数相加返回一个新的链表。 你可以假设除了数字 0 之外,这两个数字都不会以零开头。 示例: 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4) 输出:7 -> 0 -> 8 原因:342 + 465 = 807 方法一:小学数学 思路 按照小学数学中求两数之和的做法,从最低位(链表表头)开始加起,用变量 carry 保存进位的结果(初始值为0),每次求和之后更新变量 carry 的值。 Java 代码(非递归写法) /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode dummyHead =

SQL(leetcode小白刷题)自用

和自甴很熟 提交于 2020-03-03 01:24:04
@Leetcode简单题自用整理 TOC 1. 查找重复数据 题目描述 编写一个SQL查询,查找所有 重复的XXXXX ,也可以是 重复N次 的,只需改变计数条件即可。 【解题思路】 思路1 看到“找重复”的关键字眼, 首先要使用 分组函数(group by) , 再用聚合函数中的 计数函数count() 给查找的列计数。 分类汇总后,生成一个辅助表,可以从该子表中筛选查找列出计数大于1的元素,即重复的需要查找的内容。 使用辅助表结合where进行条件筛选进行嵌套子查询。 思路2 使用group by 直接在后面使用having 进行计算,筛选符合条件的。 前面提到聚合函数(count),where字句无法与聚合函数一起使用。因为where子句的运行顺序排在第二,运行到where时,表还没有被分组。 如果要对分组查询的结果进行筛选,可以使用having子句。 作者:houziAI 链接:https://leetcode-cn.com/problems/duplicate-emails/solution/tu-jie-sqlmian-shi-ti-ru-he-cha-zhao-zhong-fu-shu-/ 来源:力扣(LeetCode) 注意事项 : 1、where 后不能跟聚合函数,因为where执行顺序大于聚合函数。where > group by > having >

[LeetCode] 935. Knight Dialer 骑士拨号器

ε祈祈猫儿з 提交于 2020-03-02 08:10:06
A chess knight can move as indicated in the chess diagram below: . This time, we place our chess knight on any numbered key of a phone pad (indicated above), and the knight makes N-1 hops. Each hop must be from one key to another numbered key. Each time it lands on a key (including the initial placement of the knight), it presses the number of that key, pressing N digits total. How many distinct numbers can you dial in this manner? Since the answer may be large, output the answer modulo 10^9 + 7 . Example 1: Input: 1 Output: 10 Example 2: Input: 2 Output: 20 Example 3: Input: 3 Output: 46 Note

22. Generate Parentheses

不打扰是莪最后的温柔 提交于 2020-03-02 04:02:18
题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: 链接: http://leetcode.com/problems/generate-parentheses/ 题解: 一样也是一道回溯题,可以dfs + 回溯,也可以用dp做。 下面是回溯。 Time Complexity - n * Catalan number (n) ~ O(4 n ), Space Complexity O(n 2 ) public class Solution { public List<String> generateParenthesis(int n) { List<String> res = new ArrayList<>(); if(n <= 0) return res; String str = new String(); dfs(res, str, n, n); return res; } private void dfs(List<String> res, String str, int leftP, int rightP) { if

LeetCode:Bulls and Cows

那年仲夏 提交于 2020-03-02 00:05:44
1、题目名称 Bulls and Cows(猜数字游戏) 2、题目地址 https://leetcode.com/problems/bulls-and-cows/ 3、题目内容 英文:You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret number and ask your friend to guess it, each time your friend guesses a number, you give a hint, the hint tells your friend how many digits are in the correct positions (called "bulls") and how many digits are in the wrong positions (called "cows"), your friend will use those hints to find out the secret number. 中文:假设你正在玩猜数字游戏(Bulls and Cows):你写出4个数字让你的朋友猜,每次你的朋友猜一个数字,你给出一条线索,这个线索告诉你的朋友,有多少个数字位置是正确的(被称为Bulls)

[算法][LeetCode] 数组

感情迁移 提交于 2020-03-01 22:45:00
[算法][LeetCode]Search a 2D Matrix——二维数组的二分查找 http://www.cnblogs.com/hiddenfox/p/3402797.html 将排序的二维数组看做一维数组来处理。不重构数据的情况下,将二分查找的一维坐标转化成二维数组的坐标。 [算法][LeetCode]Spiral Matrix——螺旋矩阵 [算法][LeetCode]Single Number——异或运算的巧妙运用 对元素的出现次数进行统计,可进行n*n循环,判断元素是否只出现了一次。这样时间复杂度为O(n^2), 不需要额外空间。 先对元素进行排序,然后进行 相邻两元素的对比 ,如a1和a2对比,a3和a4对比,如果不同,则前一个元素(a1、a3)就是所要查找的元素。 异或 Single NumberII 出现3次,有一个出现一次,找出一次这个 链接: https://www.nowcoder.com/questionTerminal/1097ca585245418ea2efd0e8b4d9eb7a Single Number的本质,就是用一个数记录每个bit出现的次数,如果一个bit出现两次就归0,这种运算采用二进制底下的位操作^是很自然的。Single Number II中,如果能定义三进制底下的某种位操作,也可以达到相同的效果,Single Number

LeetCode:Gray Code

泄露秘密 提交于 2020-03-01 21:07:54
1、题目名称 Gray Code(格雷码) 2、题目地址 https://leetcode.com/problems/gray-code/ 3、题目内容 英文: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. 中文: 格雷码是一个二进制数字系统,在该系统中两个相邻的数字仅相差1个二进制位(比特)。 给出一个非负数字n,打印由n个二进制位组成的格雷码序列。格雷码序列的首个元素必须是0。 说明: 在n给定的情况下,按照上面定义(两个相邻数字仅相差1个二进制位),可以有多种格雷码的编码方案。比如n=2时,除了[0,1,3,2]外,[0,2,3,1]也是满足定义的,目前的OJ校验时只支持一种格雷码的编码方案,对此我们(出题人)表示抱歉。 4、解题方法 在题目说明中已经说明了“只支持一种格雷码的编码方案”