- 博客(26)
- 资源 (2)
- 收藏
- 关注
原创 贪吃蛇游戏 c++代码 ↑,↓,→,←分别控制蛇的方向 增加蛇长 随机生成食物 吃食物 吃撞墙 撞到自己
贪吃蛇游戏 c++代码↑,↓,→,←分别控制蛇的方向增加蛇长随机生成食物吃食物吃撞墙 撞到自己Snake.h文件#pragma once#include <stdio.h>#include <stdlib.h>#include <windows.h> //windows API函数#include<conio.h>#inclu...
2019-05-08 16:49:31
3793
1
原创 319. Bulb Switcher灯泡开关
初始时有 n 个灯泡关闭。 第 1 轮,你打开所有的灯泡。 第 2 轮,每两个灯泡你关闭一次。 第 3 轮,每三个灯泡切换一次开关(如果关闭则开启,如果开启则关闭)。第 i 轮,每 i 个灯泡切换一次开关。 对于第 n 轮,你只切换最后一个灯泡的开关。 找出 n 轮后有多少个亮着的灯泡。Example:Input: 3Output: 1Explanation:初始时, 灯泡状态 [关...
2018-12-28 11:34:11
236
原创 【Leetcode】777. Swap Adjacent in LR String在LR字符串中交换相邻字符
在一个由 ‘L’ , ‘R’ 和 ‘X’ 三个字符组成的字符串(例如"RXXLRXRXL")中进行移动操作。一次移动操作指用一个"LX"替换一个"XL",或者用一个"XR"替换一个"RX"。现给定起始字符串start和结束字符串end,请编写代码,当且仅当存在一系列移动操作使得start可以转换成end时, 返回True。Example:Input: start = “RXXLRXRXL”, ...
2018-12-28 11:14:03
330
原创 【Leetcode 921+ 763】921. Minimum Add to Make Parentheses Valid + 763. Partition Labels
给定一个由 ‘(’ 和 ‘)’ 括号组成的字符串 S,我们需要添加最少的括号( ‘(’ 或是 ‘)’,可以在任何位置),以使得到的括号字符串有效。从形式上讲,只有满足下面几点之一,括号字符串才是有效的:它是一个空字符串,或者它可以被写成 AB (A 与 B 连接), 其中 A 和 B 都是有效字符串,或者它可以被写作 (A),其中 A 是有效字符串。给定一个括号字符串,返回为使结果字符串...
2018-12-13 10:11:53
160
原创 118. Pascal's Triangle杨辉三角
Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle.In Pascal’s triangle, each number is the sum of the two numbers directly above it.Example:Input: 5Output:[[1...
2018-12-12 17:28:25
120
原创 【Leetcode】841. Keys and Rooms钥匙和房间
Keys and Rooms钥匙和房间钥匙和房间有 N 个房间,开始时你位于 0 号房间。每个房间有不同的号码:0,1,2,…,N-1,并且房间里可能有一些钥匙能使你进入下一个房间。在形式上,对于每个房间 i 都有一个钥匙列表 rooms[i],每个钥匙 rooms[i][j] 由 [0,1,…,N-1] 中的一个整数表示,其中 N = rooms.length。 钥匙 rooms[i]...
2018-12-12 11:10:01
158
原创 【Leetcode】67. Add Binary 二进制求和
Add Binary 二进制求和给定两个二进制字符串,返回他们的和(用二进制表示)。输入为非空字符串且只包含数字 1 和 0。示例 1:输入: a = “11”, b = “1”输出: “100”示例 2:输入: a = “1010”, b = “1011”输出: “10101”【思路】这题的关键是看进位class Solution {public: stri...
2018-12-12 09:45:21
253
原创 【Leetcode】703. Kth Largest Element in a Stream
【题目大意】求数据流中的第K大元素int k = 3;int[] arr = [4,5,8,2];KthLargest kthLargest = new KthLargest(3, arr);kthLargest.add(3); // returns 4kthLargest.add(5); // returns 5kthLargest.add(10); // returns ...
2018-12-11 11:25:21
136
原创 [leetcode]225. Implement Stack using Queues用队列实现栈
Implement Stack using Queues 用队列实现栈使用队列实现栈的下列操作:push(x) – 元素 x 入栈pop() – 移除栈顶元素top() – 获取栈顶元素empty() – 返回栈是否为空注意:你只能使用队列的基本操作-- 也就是 push to back, peek/pop from front, size, 和 is empty 这些操作是合法...
2018-12-10 16:36:31
119
原创 232. Implement Queue using Stacks 用栈实现队列
Implement Queue using Stacks用栈实现队列使用栈实现队列的下列操作:push(x) – 将一个元素放入队列的尾部。pop() – 从队列首部移除元素。peek() – 返回队列首部的元素。empty() – 返回队列是否为空。示例:MyQueue queue = new MyQueue();queue.push(1);queue.push(2);qu...
2018-12-10 16:10:50
300
原创 707. Design Linked List 设计链表
Design Linked List设计链表设计链表的实现。您可以选择使用单链表或双链表。单链表中的节点应该具有两个属性:val 和 next。val 是当前节点的值,next 是指向下一个节点的指针/引用。如果要使用双向链表,则还需要一个属性 prev 以指示链表中的上一个节点。假设链表中的所有节点都是 0-index 的。在链表类中实现这些功能:get(index):获取链表中第 i...
2018-12-10 15:35:11
108
原创 944. Delete Columns to Make Sorted删列造序
给定由 N 个小写字母字符串组成的数组 A,其中每个字符串长度相等。选取一个删除索引序列,对于 A 中的每个字符串,删除对应每个索引处的字符。 所余下的字符串行从上往下读形成列。比如,有 A = [“abcdef”, “uvwxyz”],删除索引序列 {0, 2, 3},删除后 A 为[“bef”, “vyz”], A 的列分别为[“b”,“v”], [“e”,“y”], [“f”,“z”]。...
2018-12-07 17:33:02
194
原创 【Leetcode】874. Walking Robot Simulation模拟行走机器人
Walking Robot Simulation模拟行走机器人模拟行走机器人机器人在一个无限大小的网格上行走,从点 (0, 0) 处开始出发,面向北方。该机器人可以接收以下三种类型的命令:-2:向左转 90 度-1:向右转 90 度1 <= x <= 9:向前移动 x 个单位长度在网格上有一些格子被视为障碍物。第 i 个障碍物位于网格点 (obstacles[i][0...
2018-12-07 17:02:15
274
原创 【Leetcode】455. Assign Cookies分发饼干
Assign CookiesAssume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minim...
2018-12-07 11:11:29
168
原创 【Leetcode】121. Best Time to Buy and Sell Stock买卖股票的最佳时机
Best Time to Buy and Sell Stock相关题目Best Time to Buy and Sell StockIISay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete a...
2018-12-07 10:30:07
130
原创 【Leetcode】122. Best Time to Buy and Sell Stock II买卖股票的最佳时机 II
Best Time to Buy and Sell Stock II买卖股票的最佳时机 II买卖股票的最佳时机 IISay you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You...
2018-12-07 09:55:53
197
原创 【leetcode】350. Intersection of Two Arrays II
Intersection of Two Arrays IIGiven two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2,2]Example 2:Input: nums1 = [4,9,5], num...
2018-12-06 11:52:03
130
原创 【Leetcode】349. Intersection of Two Arrays两个数组的交集
Intersection of Two Arrays两个数组的交集Given two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]Example 2:Input: nums1 = [4,9,5], n...
2018-12-06 11:25:42
114
原创 【Leetcode】9. Palindrome Number回文数
Palindrome NumberDetermine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。Example 1:Input: ...
2018-12-04 18:26:23
171
原创 【Leetcode】113. Path Sum II 路径总和 II
Path Sum IIGiven a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.Note: A leaf is a node with no children.Example:Given the below binary tree and su...
2018-12-04 15:18:45
132
原创 112. Path Sum
Path SumGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note: A leaf is a node with no children....
2018-12-04 10:18:41
111
原创 【Leetcode】404. Sum of Left Leaves
Sum of Left Leaves 左叶子之和[思路]:此题的关键在于如何判断是否是左子叶。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int ...
2018-11-30 15:18:54
115
原创 【Leetcode】235. Lowest Common Ancestor of a Binary Search Tree二叉搜索树的最近公共祖先
Lowest Common Ancestor of a Binary Search Tree二叉搜索树的最近公共祖先Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA o...
2018-11-30 11:10:25
173
原创 202. Happy Number 快乐数
Happy NumberWrite an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of ...
2018-11-29 17:59:38
165
原创 [Leetcode ]290. Word Pattern
Word PatternEasyGiven a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty w...
2018-11-29 17:20:48
116
原创 Leetcode [150. Evaluate Reverse Polish Notation
Leetcode [150. Evaluate Reverse Polish NotationEvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another exp...
2018-11-22 09:44:35
107
stateflow教程
2018-12-10
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人