Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Get the longest consecutive occurence of a character in a given string and the position of the start of the sequence.
- def sequence(str, pos, len)
- Change the behavior of the code if the programming language you use does not accept pass by reference.
- public class JeromeSevilla {
- public static void main(String[] args) {
- JeromeSevilla js = new JeromeSevilla();
- PosLen posLen = seq("asdfffffsdfsdttmmmmmdf");
- System.out.println("len = " + posLen.getLen() + " pos " + posLen.getPos())
- }
- public PosLen seq(String str) {
- int pos = 0;
- int len = 0;
- int lastPos = 0;
- int longest = 0;
- for (int i = 0; i < str.length() - 1; i++ ) {
- if (str.charAt(i) == str.charAt(i + 1)) {
- if (len == 0)
- pos = i;
- len ++;
- } else {
- if (len > longest) {
- longest = len;
- lastPos = pos;
- }
- pos = 0;
- len = 0;
- }
- }
- return new PosLen(lastPos, longest);
- }
- }
- public class PosLen {
- private int pos;
- private int len;
- public PosLen(int pos, int len) {
- this.pos = pos;
- this.len = len;
- }
- // getters
- }
- 2. two integers a and b, ascending blahblah, if odd +, if even *, if a is < b return a ifa == b return a + b
- ex: func(3, 6)
- (((3 + 4) * 5) + 6))
- func(3, 3)
- 3
- func(4, 3)
- 4
- public int test(int a, int b) {
- return (a < b) ? a : (a == b) ? a + b : ;
- return (a % 2 == 0) ? a + func( //hangga kumu keni, megisan oras,
- // mimisip kung mag recursion sana para pogi points
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement