38th 外观数列 简单模拟 根据题目描述,简单的模拟一遍即可。 class Solution { public String countAndSay(int n) { StringBuilder sb = new StringBuilder("1"); for (int k = 1; k < n; ...
分类:
其他好文 时间:
2020-07-06 16:12:20
阅读次数:
62
class Solution { public: bool makesquare(vector<int>& nums) { int l=nums.size(); int sum=0; for(int i=0;i<l;i++) { sum+=nums[i]; } if(sum==0 || (sum/4 ...
分类:
其他好文 时间:
2020-07-06 16:11:42
阅读次数:
36
class Solution: def strStr(self, haystack: str, needle: str) -> int: # 判断needle是否为NOne或者为空字符串 if not needle or len(needle) == 0: return 0 # 定义两个变量,用来接 ...
分类:
其他好文 时间:
2020-07-06 11:10:15
阅读次数:
49
链接:LeetCode [Leetcode]5452. 判断能否形成等差数列 给你一个数字数组 arr 。如果一个数列中,任意相邻两项的差总等于同一个常数,那么这个数列就称为 等差数列 。 如果可以重新排列数组形成等差数列,请返回 true ;否则,返回 false 。 排序后暴力即可。 class ...
分类:
其他好文 时间:
2020-07-06 10:47:00
阅读次数:
56
28th 实现 strStr() 滑动窗口思想/简单模拟 一个外循环用来遍历大串,一个内循环(或调substring函数)用来比对元素。 class Solution { public int strStr(String haystack, String needle) { int l = need ...
分类:
其他好文 时间:
2020-07-06 10:32:37
阅读次数:
61
反转字符串 题目描述 示例 Java代码 class Solution { //思想:前后位置交换 public void reverseString(char[] s) { //标记数组首 int left = 0; //标记数组尾 int right = s.length-1; //临时变量,初 ...
分类:
其他好文 时间:
2020-07-06 01:11:26
阅读次数:
63
这题和LeetCode第51题做法一样,只不过不是记录具体方案,而是个数。分析见第51题。 代码如下: class Solution { int res = 0; int n; vector<string> path; vector<bool> cols, diagram, anti_diagram ...
分类:
其他好文 时间:
2020-07-06 01:04:24
阅读次数:
54
class Solution { public int[] runningSum(int[] nums) { int temp=0; int[] b=new int[nums.length]; for (int i = 0; i < nums.length; i++) { temp=temp+num ...
分类:
编程语言 时间:
2020-07-06 00:53:54
阅读次数:
52
思路 两个数组或者字符串进行比较,本质上是一种枚举,而减少枚举次数的有效方法是使用动态规划。 用一个二维数组记录状态变化,dp[i][j]表示Si和Pj是否匹配。(Si表示字符串中前 i 个字符长度的子字符串,Pj同理) 状态方程: 代码 class Solution { public boolea... ...
分类:
其他好文 时间:
2020-07-05 22:47:25
阅读次数:
63
题目传送门 分析: 直接膜拜大佬博客OrzOrzOrz #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<iostream> #include<map> # ...
分类:
其他好文 时间:
2020-07-05 22:44:57
阅读次数:
59