2017/11/6 Leetcode 日记
2017/11/6 Leetcode 日记
344. Reverse String
Write a function that takes a string as input and returns the string reversed.
- class Solution {
- public:
- string reverseString(string s) {
- int i = , sz = s.size()-;
- for(i = ; i < sz; i++, sz--){
- char temp = s[i];
- s[i] = s[sz];
- s[sz] = temp;
- }
- return s;
- }
- };
c++
- class Solution:
- def reverseString(self, s):
- """
- :type s: str
- :rtype: str
- """
- return s[::-]
python3
575. Distribute Candies
Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these candies equally in number to brother and sister. Return the maximum number of kinds of candies the sister could gain.
Note:
- The length of the given array is in range [2, 10,000], and will be even.
- The number in given array is in range [-100,000, 100,000].
- class Solution {
- public:
- int distributeCandies(vector<int>& candies) {
- int sz = candies.size();
- unordered_set<int> sets = {};
- unordered_set<int>::const_iterator got;
- for(int i = ; i < sz; i++){
- got = sets.find(candies[i]);
- if (got == sets.end())
- sets.insert(candies[i]);
- }
- if (sets.size() <= sz/) return sets.size();
- else return sz/;
- }
- };
c++
2017/11/6 Leetcode 日记的更多相关文章
- 2017/11/22 Leetcode 日记
2017/11/22 Leetcode 日记 136. Single Number Given an array of integers, every element appears twice ex ...
- 2017/11/21 Leetcode 日记
2017/11/21 Leetcode 日记 496. Next Greater Element I You are given two arrays (without duplicates) num ...
- 2017/11/13 Leetcode 日记
2017/11/13 Leetcode 日记 463. Island Perimeter You are given a map in form of a two-dimensional intege ...
- 2017/11/20 Leetcode 日记
2017/11/14 Leetcode 日记 442. Find All Duplicates in an Array Given an array of integers, 1 ≤ a[i] ≤ n ...
- 2017/11/9 Leetcode 日记
2017/11/9 Leetcode 日记 566. Reshape the Matrix In MATLAB, there is a very useful function called 'res ...
- 2017/11/7 Leetcode 日记
2017/11/7 Leetcode 日记 669. Trim a Binary Search Tree Given a binary search tree and the lowest and h ...
- 2017/11/5 Leetcode 日记
2017/11/5 Leetcode 日记 476. Number Complement Given a positive integer, output its complement number. ...
- 2017/11/3 Leetcode 日记
2017/11/3 Leetcode 日记 654. Maximum Binary Tree Given an integer array with no duplicates. A maximum ...
- jingchi.ai 2017.11.25-26 Onsite面试
时间:2017.11.25 - 11.26 地点:安徽安庆 来回路费报销,住宿报销. day1: 大哥哥问了我一个实际中他们遇到的问题.有n个点,将点进行分块输出,输出各个块的均值点.具体就是100* ...
随机推荐
- HDU 3977 斐波那契循环节
这类型的题目其实没什么意思..知道怎么做后,就有固定套路了..而且感觉这东西要出的很难的话,有这种方法解常数会比较大吧..所以一般最多套一些比较简单的直接可以暴力求循环节的题目了.. /** @Dat ...
- Integer Numbers
ZOJ Problem Set - 3365 Integer Numbers Time Limit: 1 Second Memory Limit: 32768 KB Special ...
- ItemCF_基于物品的协同过滤
ItemCF_基于物品的协同过滤 1. 概念 2. 原理 如何给用户推荐? 给用户推荐他没有买过的物品--103 3. java代码实现思路 数据集: 第一步:构建物品的同现矩阵 第 ...
- 理解 CSS 中的伪元素 :before 和 :after
CSS 的主要目的是给 HTML 元素添加样式,然而,在一些案例中给文档添加额外的元素是多余的或是不可能的.事实上 CSS 中有一个特性允许我们添加额外元素而不扰乱文档本身,这就是“伪元素”. 你一定 ...
- 【Codeforces811E】Vladik and Entertaining Flags [线段树][并查集]
Vladik and Entertaining Flags Time Limit: 20 Sec Memory Limit: 512 MB Description n * m的矩形,每个格子上有一个 ...
- Windows.event
获取鼠标位置 document.getElementById('div').onmousemove = function(e){ //--------Chrome, firefox 支持------- ...
- CodeForces - 996B
Allen wants to enter a fan zone that occupies a round square and has nn entrances. There already is ...
- yii2-widget-fileinput英文文档翻译
源地址:http://plugins.krajee.com/file-input 该插件是为bootstrap开发的增强版h5文件上传插件,具有多文件预览,多文件选择等功能.该插件提供了基于boots ...
- python 实现字符串转整型
def str2Int(s): l=list(s) if len(l)<=0: return 0 flag=0 sum=0 dict_num={':9} dict_tag={'+':1,'-': ...
- Serv-U设置允许用户更改密码【转】
最近,公司上了一套Serv-U10.5.0.6的ftp软件,应该是目前最新的版本了.上的第一天就遇到了一个问题,有领导发话了,他需要自己更改密码.找了N久才找到,分享一下. 点击管理界面的用户. 进入 ...