• Longest Substring Without Repeating Characters解题报告


    使用双指针,i遍历全部字符,start收集重复的次数,最后不重复出现的字符个数maxx为i-start+1;

      1 //
      2 
      3 //  main.cpp
      4 
      5 //  Longest Substring
      6 
      7 //
      8 
      9 //  Created by Bowie Hsu  on 14/11/21.
     10 
     11 //  Copyright (c) 2014年 Bowie Hsu . All rights reserved.
     12 
     13 //
     14 
     15  
     16 
     17 #include <iostream>
     18 
     19 #include <string>
     20 
     21 #include <vector>
     22 
     23 #include "stdio.h"
     24 
     25 using namespace std;
     26 
     27  
     28 
     29  struct ListNode {
     30 
     31          int val;   //用将x的值赋给int型
     32 
     33          ListNode *next;
     34 
     35          ListNode(int x) : val(x), next(NULL) {}
     36 
     37      };
     38 
     39  
     40 
     41 class Solution {
     42 
     43 public:
     44 
     45 public:
     46 
     47     ListNode *addTwoNumbers(ListNode *l1, ListNode *l2)
     48 
     49     {
     50 
     51         int forw=0;//进位标志
     52 
     53         //建立一个新的链表存储答案
     54 
     55         ListNode root(0);
     56 
     57         ListNode *output=&root;
     58 
     59         while(l1||l2)
     60 
     61         {
     62 
     63             int v1 = (l1 ? l1->val : 0);
     64 
     65             int v2 = (l2 ? l2->val : 0);
     66 
     67             int sum=v1+v2+forw;
     68 
     69             //检验sum是否为两位数
     70 
     71             forw=sum/10;
     72 
     73             sum=sum%10;
     74 
     75             ListNode *coNode=new ListNode(sum);
     76 
     77             output->next=coNode;
     78 
     79             output=coNode;
     80 
     81             if(l1)l1=l1->next;
     82 
     83             if(l2)l2=l2->next;
     84 
     85         }
     86 
     87         if(forw>0)
     88 
     89         {
     90 
     91             ListNode *coNode=new ListNode(forw);
     92 
     93             output->next=coNode;
     94 
     95             output=coNode;
     96 
     97         }
     98 
     99         return root.next;
    100 
    101     }
    102 
    103 };
    104 
    105  
    106 
    107 int main()
    108 
    109 {
    110 
    111     Solution x;
    112 
    113     ListNode newpoint(0);
    114 
    115     ListNode *ans=&newpoint;
    116 
    117     ListNode *newpoint1=new ListNode(6);
    118 
    119     ListNode *newpoint2=new ListNode(7);   
    120 
    121     ans->next=x.addTwoNumbers(newpoint2,newpoint1);
    122 
    123     cout<<ans->next->next->val<<endl;  //程序成功,输出6+7=13中的十位数字1
    124 
    125 }

     

  • 相关阅读:
    简单粗暴的tensorflowRNN
    简单粗暴的tensorflow多层感知机(MLP)
    简单粗暴的tensorflow模型导出
    Tensorflow
    简单粗暴的tensorflowTensorBoard可视化
    linux deb文件安装
    numpy.squeeze()的用法
    pandas
    图像融合opencv中addWeighted()
    numpy线性代数
  • 原文地址:https://www.cnblogs.com/bowiehsu/p/4118315.html
Copyright © 2020-2023  润新知